Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add unit tests for ExecutionResult constructors #435

Merged
merged 1 commit into from
Jul 22, 2020

Conversation

axic
Copy link
Member

@axic axic commented Jul 22, 2020

image

Either coverage is wrong, or the explicit constructor is not called. With these tests we make sure that values are always correct even if in the case Trap/Void don't get assigned via the explicit constructor, but by setting the trapped variable. We can figure out the case with coverage later (cc @chfast).

@axic axic requested a review from gumb0 July 22, 2020 14:03
@codecov
Copy link

codecov bot commented Jul 22, 2020

Codecov Report

Merging #435 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #435   +/-   ##
=======================================
  Coverage   99.32%   99.33%           
=======================================
  Files          50       50           
  Lines       14075    14107   +32     
=======================================
+ Hits        13980    14013   +33     
+ Misses         95       94    -1     

@gumb0
Copy link
Collaborator

gumb0 commented Jul 22, 2020

Do you want to try to cover the constexpr constructor line? I think this might do it

bool success = false; // non const variable
const ExecutionResult result{success};
EXPECT_FALSE(result.trapped);

@axic axic force-pushed the execution-result-tests branch from 0ebcea2 to 6029a8c Compare July 22, 2020 14:23

TEST(api, execution_result_bool_constructor)
{
bool success = false;
Copy link
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.

@axic axic force-pushed the execution-result-tests branch from 6029a8c to 4804de3 Compare July 22, 2020 14:46

TEST(api, execution_result_value)
{
const ExecutionResult result = 1234;
Copy link
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)

@axic axic force-pushed the execution-result-tests branch from 4804de3 to 37a1b40 Compare July 22, 2020 15:47
@axic axic force-pushed the execution-result-tests branch from 37a1b40 to 879005f Compare July 22, 2020 16:34
@axic axic merged commit 789ba63 into master Jul 22, 2020
@axic axic deleted the execution-result-tests branch July 22, 2020 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants