Skip to content

Commit

Permalink
Fix disappeared messages from asserts (#301)
Browse files Browse the repository at this point in the history
Regressed after porting assert and errors modules to native modules.
  • Loading branch information
Kojoley authored Jul 16, 2023
1 parent d1d7a6a commit cdab17f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
9 changes: 8 additions & 1 deletion src/engine/mod_jam_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void error_skip_frames(std::tuple<int, list_ref> skip_messages,
{
lists messages;
messages.push_back(std::move(std::get<1>(skip_messages)));
messages.append(rest);
error_skip_frames(std::get<0>(skip_messages), messages, context_ref);
}

Expand Down Expand Up @@ -195,7 +196,9 @@ void warning(const lists & rest, bind::context_ref_ context_ref)
list_ref lol_to_list(const lists & rest)
{
list_ref result;
for (lists::size_type i = 0; i < rest.length(); ++i)
lists::size_type size = rest.length();
while (size > 0 && rest[size - 1].empty()) --size;
for (lists::size_type i = 0; i < size; ++i)
{
if (i != 0) result.push_back(":");
for (auto l : rest[i])
Expand Down Expand Up @@ -230,6 +233,10 @@ if --no-error-backtrace in [ modules.peek : ARGV ]
rule __test__ ( )
{
import assert ;
assert.result \"a\" \"b\" \"c\" ":" \"d\" : lol->list a b c : d ;
# Show that we can correctly catch an expected error.
try ;
{
Expand Down
50 changes: 26 additions & 24 deletions test/BoostBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def dump_stdio(self):
annotation("STDERR", self.stderr())

def run_build_system(self, extra_args=None, subdir="", stdout=None,
stderr="", status=0, match=None, pass_toolset=None,
stderr="", status=0, match=None, match_filter=None, pass_toolset=None,
use_test_config=None, ignore_toolset_requirements=None,
expected_duration=None, **kw):

Expand Down Expand Up @@ -539,29 +539,15 @@ def run_build_system(self, extra_args=None, subdir="", stdout=None,
annotation("reason", "unexpected status returned by bjam")
self.fail_test(1)

if stdout is not None and not match(self.stdout(), stdout):
stdout_test = match(self.stdout(), stdout)
annotation("failure", "Unexpected stdout")
annotation("Expected STDOUT", stdout)
annotation("Actual STDOUT", self.stdout())
stderr = self.stderr()
if stderr:
annotation("STDERR", stderr)
self.do_diff(self.stdout(), stdout)
self.fail_test(1, dump_stdio=False)
if stdout is not None:
self.do_diff('STDOUT', self.stdout(), stdout, match, match_filter)

# Intel tends to produce some messages to stderr which make tests fail.
intel_workaround = re.compile("^xi(link|lib): executing.*\n", re.M)
actual_stderr = re.sub(intel_workaround, "", self.stderr())

if stderr is not None and not match(actual_stderr, stderr):
stderr_test = match(actual_stderr, stderr)
annotation("failure", "Unexpected stderr")
annotation("Expected STDERR", stderr)
annotation("Actual STDERR", self.stderr())
annotation("STDOUT", self.stdout())
self.do_diff(actual_stderr, stderr)
self.fail_test(1, dump_stdio=False)
if stderr is not None:
self.do_diff('STDERR', actual_stderr, stderr, match, match_filter)

if expected_duration is not None:
actual_duration = build_time_finish - build_time_start
Expand All @@ -571,6 +557,27 @@ def run_build_system(self, extra_args=None, subdir="", stdout=None,
expected_duration))
self.fail_test(1, dump_stdio=False)

def do_diff(self, what, actual, expected, matcher, match_filter):
actual_lines = actual.splitlines(keepends=True)
expected_lines = expected.splitlines(keepends=True)
if match_filter is not None:
actual_lines = list(filter(match_filter, actual_lines))
expected_lines = list(filter(match_filter, expected_lines))
match = matcher("".join(actual_lines), "".join(expected_lines))
filtered = " (filtered)"
else:
match = matcher(actual, expected)
filtered = ""
if match:
return
diff = "".join(ndiff(expected_lines, actual_lines))
annotation(f"Expected {what}", expected)
annotation(f"Actual {what}", actual)
if what.lower() == "stdout":
annotation("STDERR", self.stderr())
annotation(f"Difference in {what}{filtered}", diff)
self.fail_test(True, dump_stdio=False)

def glob_file(self, name):
name = self.adjust_name(name)
result = None
Expand Down Expand Up @@ -816,11 +823,6 @@ def sorted_(z):
print(actual)
self.fail_test(1)

def do_diff(self, actual, expected):
actual = actual.splitlines(keepends=True)
expected = expected.splitlines(keepends=True)
annotation("DIFFERENCE", "".join(ndiff(actual, expected)))

# Internal methods.
def adjust_lib_name(self, name):
global lib_prefix
Expand Down
29 changes: 29 additions & 0 deletions test/assert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3

# Copyright 2023 Nikita Kniazev
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at
# https://www.bfgroup.xyz/b2/LICENSE.txt)

# Tests assert module

import BoostBuild

t = BoostBuild.Tester(pass_toolset=False)

t.write("Jamroot", """\
import assert ;
rule foo ( ) { return 1 2 3 ; }
assert.result 1 2 4 : foo ;
""")

t.run_build_system(status=1, stdout="""\
error: assertion failure: [ foo ]
error: Expected: [ "1" "2" "4" ]
error: Got: [ "1" "2" "3" ]
""", match_filter=lambda x: "from module" not in x)
t.expect_nothing_more()

t.cleanup()
1 change: 1 addition & 0 deletions test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def reorder_tests(tests, first_test):
"alias",
"alternatives",
"always",
"assert",
"bad_dirname",
"build_dir",
"build_file",
Expand Down

0 comments on commit cdab17f

Please sign in to comment.