Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions test/unittests/api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,48 @@ ExecutionResult function_returning_void(Instance&, span<const uint64_t>, int) no
}
} // namespace

TEST(api, execution_result_trap)
{
const auto result = Trap;
EXPECT_TRUE(result.trapped);
EXPECT_FALSE(result.has_value);
EXPECT_EQ(result.value, 0);
}

TEST(api, execution_result_void)
{
const auto result = Void;
EXPECT_FALSE(result.trapped);
EXPECT_FALSE(result.has_value);
EXPECT_EQ(result.value, 0);
}

TEST(api, execution_result_value)
{
const ExecutionResult result = 1234;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ExecutionResult result{1234};

results in

/Users/alex/Projects/fizzy/test/unittests/api_test.cpp:46:27: error: call to constructor of 'const fizzy::ExecutionResult' is ambiguous
    const ExecutionResult result{1234};
                          ^     ~~~~~~
/Users/alex/Projects/fizzy/lib/fizzy/execute.hpp:25:15: note: candidate constructor
    constexpr ExecutionResult(uint64_t _value) noexcept : has_value{true}, value{_value} {}
              ^
/Users/alex/Projects/fizzy/lib/fizzy/execute.hpp:29:24: note: candidate constructor
    constexpr explicit ExecutionResult(bool success) noexcept : trapped{!success} {}
                       ^
/Users/alex/Projects/fizzy/lib/fizzy/execute.hpp:18:8: note: candidate constructor (the implicit move constructor)
struct ExecutionResult
       ^
/Users/alex/Projects/fizzy/lib/fizzy/execute.hpp:18:8: note: candidate constructor (the implicit copy constructor)

EXPECT_FALSE(result.trapped);
EXPECT_TRUE(result.has_value);
EXPECT_EQ(result.value, 1234);
}

TEST(api, execution_result_bool_constructor)
{
bool success = false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would execute the constructor with this being const, too, I'm not sure, just thought with non-const it's less probable to be optimized away.
Can be merged like this, anyway.

const ExecutionResult result{success};
EXPECT_TRUE(result.trapped);
EXPECT_FALSE(result.has_value);
EXPECT_EQ(result.value, 0);
}

TEST(api, execution_result_uint64_constructor)
{
uint64_t value = 1234;
const ExecutionResult result{value};
EXPECT_FALSE(result.trapped);
EXPECT_TRUE(result.has_value);
EXPECT_EQ(result.value, 1234);
}

TEST(api, resolve_imported_functions)
{
/* wat2wasm
Expand Down