summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tm@tlater.net>2019-01-02 18:19:27 +0100
committerTristan Maat <tristan.maat@codethink.co.uk>2019-01-18 18:03:59 +0000
commit3a408b790bfd5243f29e9fcdc553a10fcb418cce (patch)
tree16351f3580ffc3db4e80afb1c886cc5d0eb49a6b
parentd93cddcfedffa2f7ca09bd0364e4778263cd46de (diff)
downloadbuildstream-tlater/message-lines.tar.gz
widget.py: Avoid "showing 0 lines" messages when there are no linestlater/message-lines
This happened when bst is invoked with --message-lines 0 or --error-lines 0, and was arguably a little too verbose (the user explicitly asked us not to show them any lines, after all). Fixes #779
-rw-r--r--buildstream/_frontend/widget.py5
-rw-r--r--tests/integration/messages.py110
2 files changed, 113 insertions, 2 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