Skip to content

Commit

Permalink
test: Correctly output result mismatch error values in spectest runner
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Aug 7, 2020
1 parent 4f6cdf4 commit fd7fed9
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions test/spectests/spectests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ fizzy::bytes load_wasm_file(const fs::path& json_file_path, std::string_view fil
std::istreambuf_iterator<char>{wasm_file}, std::istreambuf_iterator<char>{});
}

std::ostream& operator<<(std::ostream& out, std::pair<fizzy::Value, std::string> value_and_type)
{
const auto& [value, type] = value_and_type;

if (type == "i32" || type == "i64")
out << value.i64 << " (0x" << std::hex << value.i64 << ")";
else if (type == "f32")
out << value.f32 << " (0x" << std::hex << fizzy::test::FP{value.f32}.as_uint() << ")";
else if (type == "f64")
out << value.f64 << " (0x" << std::hex << fizzy::test::FP{value.f64}.as_uint() << ")";
else
assert(false);

out << std::dec;
return out;
}

struct test_settings
{
bool skip_validation = false;
Expand Down Expand Up @@ -479,10 +496,9 @@ class test_runner
if (!is_equal)
{
std::stringstream message;
message << "Incorrect returned value. Expected: " << expected_value->i64 << " (0x"
<< std::hex << expected_value->i64 << ") Actual: " << std::dec
<< actual_value.i64 << " (0x" << std::hex << actual_value.i64 << std::dec
<< ")";
message << "Incorrect returned value. Expected: "
<< std::make_pair(*expected_value, value_type)
<< " Actual: " << std::make_pair(actual_value, value_type);
fail(message.str());
return false;
}
Expand Down

0 comments on commit fd7fed9

Please sign in to comment.