|  | 1 | +#
 | 
|  | 2 | +#  Copyright (C) 2018 Codethink Limited
 | 
|  | 3 | +#
 | 
|  | 4 | +#  This program is free software; you can redistribute it and/or
 | 
|  | 5 | +#  modify it under the terms of the GNU Lesser General Public
 | 
|  | 6 | +#  License as published by the Free Software Foundation; either
 | 
|  | 7 | +#  version 2 of the License, or (at your option) any later version.
 | 
|  | 8 | +#
 | 
|  | 9 | +#  This library is distributed in the hope that it will be useful,
 | 
|  | 10 | +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|  | 11 | +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
|  | 12 | +#  Lesser General Public License for more details.
 | 
|  | 13 | +#
 | 
|  | 14 | +#  You should have received a copy of the GNU Lesser General Public
 | 
|  | 15 | +#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 | 
|  | 16 | +#
 | 
|  | 17 | +#  Authors: Tristan Maat <tristan maat codethink co uk>
 | 
|  | 18 | +#
 | 
|  | 19 | +
 | 
|  | 20 | +import os
 | 
|  | 21 | +import pytest
 | 
|  | 22 | +
 | 
|  | 23 | +from buildstream import _yaml
 | 
|  | 24 | +from buildstream._exceptions import ErrorDomain
 | 
|  | 25 | +
 | 
|  | 26 | +from tests.testutils import cli_integration as cli
 | 
|  | 27 | +
 | 
|  | 28 | +
 | 
|  | 29 | +pytestmark = pytest.mark.integration
 | 
|  | 30 | +
 | 
|  | 31 | +
 | 
|  | 32 | +# Project directory
 | 
|  | 33 | +DATA_DIR = os.path.join(
 | 
|  | 34 | +    os.path.dirname(os.path.realpath(__file__)),
 | 
|  | 35 | +    "project",
 | 
|  | 36 | +)
 | 
|  | 37 | +
 | 
|  | 38 | +
 | 
|  | 39 | +@pytest.mark.integration
 | 
|  | 40 | +@pytest.mark.datafiles(DATA_DIR)
 | 
|  | 41 | +def test_disable_message_lines(cli, tmpdir, datafiles):
 | 
|  | 42 | +    project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
|  | 43 | +    element_path = os.path.join(project, 'elements')
 | 
|  | 44 | +    element_name = 'message.bst'
 | 
|  | 45 | +
 | 
|  | 46 | +    element = {
 | 
|  | 47 | +        'kind': 'manual',
 | 
|  | 48 | +        'depends': [{
 | 
|  | 49 | +            'filename': 'base.bst'
 | 
|  | 50 | +        }],
 | 
|  | 51 | +        'config': {
 | 
|  | 52 | +            'build-commands':
 | 
|  | 53 | +            ['echo "Silly message"'],
 | 
|  | 54 | +            'strip-commands': []
 | 
|  | 55 | +        }
 | 
|  | 56 | +    }
 | 
|  | 57 | +
 | 
|  | 58 | +    os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
 | 
|  | 59 | +    _yaml.dump(element, os.path.join(element_path, element_name))
 | 
|  | 60 | +
 | 
|  | 61 | +    # First we check that we get the "Silly message"
 | 
|  | 62 | +    result = cli.run(project=project, args=["build", element_name])
 | 
|  | 63 | +    result.assert_success()
 | 
|  | 64 | +    assert 'echo "Silly message"' in result.stderr
 | 
|  | 65 | +
 | 
|  | 66 | +    # Let's now build it again, but with --message-lines 0
 | 
|  | 67 | +    cli.remove_artifact_from_cache(project, element_name)
 | 
|  | 68 | +    result = cli.run(project=project, args=["--message-lines", "0",
 | 
|  | 69 | +                                            "build", element_name])
 | 
|  | 70 | +    result.assert_success()
 | 
|  | 71 | +    assert not "Message contains " in result.stderr
 | 
|  | 72 | +
 | 
|  | 73 | +@pytest.mark.integration
 | 
|  | 74 | +@pytest.mark.datafiles(DATA_DIR)
 | 
|  | 75 | +def test_disable_error_lines(cli, tmpdir, datafiles):
 | 
|  | 76 | +    project = os.path.join(datafiles.dirname, datafiles.basename)
 | 
|  | 77 | +    element_path = os.path.join(project, 'elements')
 | 
|  | 78 | +    element_name = 'message.bst'
 | 
|  | 79 | +
 | 
|  | 80 | +    element = {
 | 
|  | 81 | +        'kind': 'manual',
 | 
|  | 82 | +        'depends': [{
 | 
|  | 83 | +            'filename': 'base.bst'
 | 
|  | 84 | +        }],
 | 
|  | 85 | +        'config': {
 | 
|  | 86 | +            'build-commands':
 | 
|  | 87 | +            ['This is a syntax error > >'],
 | 
|  | 88 | +            'strip-commands': []
 | 
|  | 89 | +        }
 | 
|  | 90 | +    }
 | 
|  | 91 | +
 | 
|  | 92 | +    os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
 | 
|  | 93 | +    _yaml.dump(element, os.path.join(element_path, element_name))
 | 
|  | 94 | +
 | 
|  | 95 | +    # First we check that we get the syntax error
 | 
|  | 96 | +    result = cli.run(project=project, args=["--error-lines", "0",
 | 
|  | 97 | +                                            "build", element_name])
 | 
|  | 98 | +    result.assert_main_error(ErrorDomain.STREAM, None)
 | 
|  | 99 | +    assert "This is a syntax error" in result.stderr
 | 
|  | 100 | +
 | 
|  | 101 | +    # Let's now build it again, but with --error-lines 0
 | 
|  | 102 | +    cli.remove_artifact_from_cache(project, element_name)
 | 
|  | 103 | +    result = cli.run(project=project, args=["--error-lines", "0",
 | 
|  | 104 | +                                            "build", element_name])
 | 
|  | 105 | +    result.assert_main_error(ErrorDomain.STREAM, None)
 | 
|  | 106 | +    assert not "Printing the last" in result.stderr |