summaryrefslogtreecommitdiff
path: root/tests/integration/messages.py
blob: 7f4194e0ffba1644e39a81f809c624dd1e09b3a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#
#  Copyright (C) 2018 Codethink Limited
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
#
#  Authors: Tristan Maat <tristan.maat@codethink.co.uk>
#

import os
import pytest

from buildstream import _yaml
from buildstream._exceptions import ErrorDomain
from buildstream.plugintestutils import cli_integration as cli
from tests.testutils.site import HAVE_SANDBOX


pytestmark = pytest.mark.integration


# Project directory
DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    "project",
)


@pytest.mark.integration
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.skipif(not HAVE_SANDBOX, reason='Only available with a functioning sandbox')
def test_disable_message_lines(cli, tmpdir, datafiles):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    element_path = os.path.join(project, 'elements')
    element_name = 'message.bst'

    element = {
        'kind': 'manual',
        'depends': [{
            'filename': 'base.bst'
        }],
        'config': {
            'build-commands':
            ['echo "Silly message"'],
            'strip-commands': []
        }
    }

    os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
    _yaml.dump(element, os.path.join(element_path, element_name))

    # First we check that we get the "Silly message"
    result = cli.run(project=project, args=["build", element_name])
    result.assert_success()
    assert 'echo "Silly message"' in result.stderr

    # Let's now build it again, but with --message-lines 0
    cli.remove_artifact_from_cache(project, element_name)
    result = cli.run(project=project, args=["--message-lines", "0",
                                            "build", element_name])
    result.assert_success()
    assert "Message contains " not in result.stderr


@pytest.mark.integration
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.skipif(not HAVE_SANDBOX, reason='Only available with a functioning sandbox')
def test_disable_error_lines(cli, tmpdir, datafiles):
    project = os.path.join(datafiles.dirname, datafiles.basename)
    element_path = os.path.join(project, 'elements')
    element_name = 'message.bst'

    element = {
        'kind': 'manual',
        'depends': [{
            'filename': 'base.bst'
        }],
        'config': {
            'build-commands':
            ['This is a syntax error > >'],
            'strip-commands': []
        }
    }

    os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
    _yaml.dump(element, os.path.join(element_path, element_name))

    # First we check that we get the syntax error
    result = cli.run(project=project, args=["--error-lines", "0",
                                            "build", element_name])
    result.assert_main_error(ErrorDomain.STREAM, None)
    assert "This is a syntax error" in result.stderr

    # Let's now build it again, but with --error-lines 0
    cli.remove_artifact_from_cache(project, element_name)
    result = cli.run(project=project, args=["--error-lines", "0",
                                            "build", element_name])
    result.assert_main_error(ErrorDomain.STREAM, None)
    assert "Printing the last" not in result.stderr