| 
 
 | 
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
 | 
+from tests.testutils.site import HAVE_BWRAP, IS_LINUX
 
 | 
| 
 
 | 
28
 | 
+
 
 | 
| 
 
 | 
29
 | 
+
 
 | 
| 
 
 | 
30
 | 
+pytestmark = pytest.mark.integration
 
 | 
| 
 
 | 
31
 | 
+
 
 | 
| 
 
 | 
32
 | 
+
 
 | 
| 
 
 | 
33
 | 
+# Project directory
 
 | 
| 
 
 | 
34
 | 
+DATA_DIR = os.path.join(
 
 | 
| 
 
 | 
35
 | 
+    os.path.dirname(os.path.realpath(__file__)),
 
 | 
| 
 
 | 
36
 | 
+    "project",
 
 | 
| 
 
 | 
37
 | 
+)
 
 | 
| 
 
 | 
38
 | 
+
 
 | 
| 
 
 | 
39
 | 
+
 
 | 
| 
 
 | 
40
 | 
+@pytest.mark.integration
 
 | 
| 
 
 | 
41
 | 
+@pytest.mark.datafiles(DATA_DIR)
 
 | 
| 
 
 | 
42
 | 
+@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
 
 | 
| 
 
 | 
43
 | 
+def test_disable_message_lines(cli, tmpdir, datafiles):
 
 | 
| 
 
 | 
44
 | 
+    project = os.path.join(datafiles.dirname, datafiles.basename)
 
 | 
| 
 
 | 
45
 | 
+    element_path = os.path.join(project, 'elements')
 
 | 
| 
 
 | 
46
 | 
+    element_name = 'message.bst'
 
 | 
| 
 
 | 
47
 | 
+
 
 | 
| 
 
 | 
48
 | 
+    element = {
 | 
| 
 
 | 
49
 | 
+        'kind': 'manual',
 
 | 
| 
 
 | 
50
 | 
+        'depends': [{
 | 
| 
 
 | 
51
 | 
+            'filename': 'base.bst'
 
 | 
| 
 
 | 
52
 | 
+        }],
 
 | 
| 
 
 | 
53
 | 
+        'config': {
 | 
| 
 
 | 
54
 | 
+            'build-commands':
 
 | 
| 
 
 | 
55
 | 
+            ['echo "Silly message"'],
 
 | 
| 
 
 | 
56
 | 
+            'strip-commands': []
 
 | 
| 
 
 | 
57
 | 
+        }
 
 | 
| 
 
 | 
58
 | 
+    }
 
 | 
| 
 
 | 
59
 | 
+
 
 | 
| 
 
 | 
60
 | 
+    os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
 
 | 
| 
 
 | 
61
 | 
+    _yaml.dump(element, os.path.join(element_path, element_name))
 
 | 
| 
 
 | 
62
 | 
+
 
 | 
| 
 
 | 
63
 | 
+    # First we check that we get the "Silly message"
 
 | 
| 
 
 | 
64
 | 
+    result = cli.run(project=project, args=["build", element_name])
 
 | 
| 
 
 | 
65
 | 
+    result.assert_success()
 
 | 
| 
 
 | 
66
 | 
+    assert 'echo "Silly message"' in result.stderr
 
 | 
| 
 
 | 
67
 | 
+
 
 | 
| 
 
 | 
68
 | 
+    # Let's now build it again, but with --message-lines 0
 
 | 
| 
 
 | 
69
 | 
+    cli.remove_artifact_from_cache(project, element_name)
 
 | 
| 
 
 | 
70
 | 
+    result = cli.run(project=project, args=["--message-lines", "0",
 
 | 
| 
 
 | 
71
 | 
+                                            "build", element_name])
 
 | 
| 
 
 | 
72
 | 
+    result.assert_success()
 
 | 
| 
 
 | 
73
 | 
+    assert "Message contains " not in result.stderr
 
 | 
| 
 
 | 
74
 | 
+
 
 | 
| 
 
 | 
75
 | 
+
 
 | 
| 
 
 | 
76
 | 
+@pytest.mark.integration
 
 | 
| 
 
 | 
77
 | 
+@pytest.mark.datafiles(DATA_DIR)
 
 | 
| 
 
 | 
78
 | 
+@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
 
 | 
| 
 
 | 
79
 | 
+def test_disable_error_lines(cli, tmpdir, datafiles):
 
 | 
| 
 
 | 
80
 | 
+    project = os.path.join(datafiles.dirname, datafiles.basename)
 
 | 
| 
 
 | 
81
 | 
+    element_path = os.path.join(project, 'elements')
 
 | 
| 
 
 | 
82
 | 
+    element_name = 'message.bst'
 
 | 
| 
 
 | 
83
 | 
+
 
 | 
| 
 
 | 
84
 | 
+    element = {
 | 
| 
 
 | 
85
 | 
+        'kind': 'manual',
 
 | 
| 
 
 | 
86
 | 
+        'depends': [{
 | 
| 
 
 | 
87
 | 
+            'filename': 'base.bst'
 
 | 
| 
 
 | 
88
 | 
+        }],
 
 | 
| 
 
 | 
89
 | 
+        'config': {
 | 
| 
 
 | 
90
 | 
+            'build-commands':
 
 | 
| 
 
 | 
91
 | 
+            ['This is a syntax error > >'],
 
 | 
| 
 
 | 
92
 | 
+            'strip-commands': []
 
 | 
| 
 
 | 
93
 | 
+        }
 
 | 
| 
 
 | 
94
 | 
+    }
 
 | 
| 
 
 | 
95
 | 
+
 
 | 
| 
 
 | 
96
 | 
+    os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
 
 | 
| 
 
 | 
97
 | 
+    _yaml.dump(element, os.path.join(element_path, element_name))
 
 | 
| 
 
 | 
98
 | 
+
 
 | 
| 
 
 | 
99
 | 
+    # First we check that we get the syntax error
 
 | 
| 
 
 | 
100
 | 
+    result = cli.run(project=project, args=["--error-lines", "0",
 
 | 
| 
 
 | 
101
 | 
+                                            "build", element_name])
 
 | 
| 
 
 | 
102
 | 
+    result.assert_main_error(ErrorDomain.STREAM, None)
 
 | 
| 
 
 | 
103
 | 
+    assert "This is a syntax error" in result.stderr
 
 | 
| 
 
 | 
104
 | 
+
 
 | 
| 
 
 | 
105
 | 
+    # Let's now build it again, but with --error-lines 0
 
 | 
| 
 
 | 
106
 | 
+    cli.remove_artifact_from_cache(project, element_name)
 
 | 
| 
 
 | 
107
 | 
+    result = cli.run(project=project, args=["--error-lines", "0",
 
 | 
| 
 
 | 
108
 | 
+                                            "build", element_name])
 
 | 
| 
 
 | 
109
 | 
+    result.assert_main_error(ErrorDomain.STREAM, None)
 
 | 
| 
 
 | 
110
 | 
+    assert "Printing the last" not in result.stderr 
 |