summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2019-01-18 23:23:35 +0000
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2019-01-18 23:23:35 +0000
commite230dedba3b5daac6d1d1f006bff792c10b9cf60 (patch)
tree6d95ef8ba13593360a49284b8bb7b465824b3d03
parent2233a532b88bbf2f25ea04efe1abf47871bc3aad (diff)
parentfff882fef95f1f66fd8619d386b208f6ab64470a (diff)
downloadbuildstream-e230dedba3b5daac6d1d1f006bff792c10b9cf60.tar.gz
Merge branch 'tlater/message-lines' into 'master'
Avoid "showing 0 lines" messages when we're asked to show no lines Closes #779 See merge request BuildStream/buildstream!1031
-rw-r--r--buildstream/_frontend/widget.py5
-rw-r--r--tests/integration/messages.py110
-rw-r--r--tests/testutils/runcli.py8
3 files changed, 120 insertions, 3 deletions
diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py
index a9e5eeafb..30c2e9e1a 100644
--- a/buildstream/_frontend/widget.py
+++ b/buildstream/_frontend/widget.py
@@ -647,8 +647,9 @@ class LogLine(Widget):
abbrev = False
if message.message_type not in ERROR_MESSAGES \
and not frontend_message and n_lines > self._message_lines:
- abbrev = True
lines = lines[0:self._message_lines]
+ if self._message_lines > 0:
+ abbrev = True
else:
lines[n_lines - 1] = lines[n_lines - 1].rstrip('\n')
@@ -674,7 +675,7 @@ class LogLine(Widget):
if self.context is not None and not self.context.log_verbose:
text += self._indent + self._err_profile.fmt("Log file: ")
text += self._indent + self._logfile_widget.render(message) + '\n'
- else:
+ elif self._log_lines > 0:
text += self._indent + self._err_profile.fmt("Printing the last {} lines from log file:"
.format(self._log_lines)) + '\n'
text += self._indent + self._logfile_widget.render(message, abbrev=False) + '\n'
diff --git a/tests/integration/messages.py b/tests/integration/messages.py
new file mode 100644
index 000000000..775921cba
--- /dev/null
+++ b/tests/integration/messages.py
@@ -0,0 +1,110 @@
+#
+# 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 tests.testutils import cli_integration as cli
+from tests.testutils.site import HAVE_BWRAP, IS_LINUX
+
+
+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(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
+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(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
+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
diff --git a/tests/testutils/runcli.py b/tests/testutils/runcli.py
index d3f5113a0..7cd81e0a6 100644
--- a/tests/testutils/runcli.py
+++ b/tests/testutils/runcli.py
@@ -245,8 +245,14 @@ class Cli():
def remove_artifact_from_cache(self, project, element_name,
*, cache_dir=None):
+ # Read configuration to figure out where artifacts are stored
if not cache_dir:
- cache_dir = os.path.join(project, 'cache', 'artifacts')
+ default = os.path.join(project, 'cache', 'artifacts')
+
+ if self.config is not None:
+ cache_dir = self.config.get('artifactdir', default)
+ else:
+ cache_dir = default
cache_dir = os.path.join(cache_dir, 'cas', 'refs', 'heads')