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

Lambda capture seems to prevent source file name being obtained #434

Open
claremacrae opened this issue Apr 9, 2021 · 5 comments
Open

Comments

@claremacrae
Copy link
Contributor

claremacrae commented Apr 9, 2021

Expected Behavior

That the filename obtained from a custom reporter should be valid, in this code - which can be run at https://godbolt.org/z/13Y7Wq1r7

#define APPROVALS_UT
#include "MinimalApprovalTests.h"

int main()
{
    using namespace boost::ut;
    using namespace ApprovalTests;

    "VerifyAFileWithAmpersand&"_test = [&]() { // <<< Changing [&] to [] makes the test pass
        ApprovalTestNamer namer;

        auto name = namer.getSourceFileName();
        expect(name == "ut_starter_test") << "value was:" << name; // <<< this test fails - the name is unknown

        auto test_case = namer.getTestName();
        expect(test_case == "VerifyAFileWithAmpersand&") << "value was:" << test_case;
    };
}

Actual Behavior

Two different users of Approval Tests have reported that when a lambda capture is used, the source name is reported as 'unknown':

Steps to Reproduce the Problem

I've created a massively cut-down version of the Approval Tests code, for a minimal example. It took some hours - I hope it makes it easier to track down the problem:

  1. Run the code in https://godbolt.org/z/13Y7Wq1r7
  2. The test on line 419 fails. It should pass

If downloading this code to run locally, you will need to:

  1. Edit line 73 to change include your boost/ut.hpp instead of #include <https://raw.githubusercontent.com/boost-ext/ut/master/include/boost/ut.hpp>
  2. Edit line 419 to change __stdin__ to be the base name (file without extension) of the source file you saved.

Specifications

  • Version: ffe66dd
  • Platform: Tested on Mac and Linux - the Godbolt example is using gcc trunk
  • Subsystem: Unsure
@claremacrae claremacrae changed the title Lambda capture causes Lambda capture seems to prevent source file name being obtained Apr 9, 2021
@sam20908
Copy link
Contributor

I have figured out a possible fix. This involves using the actual <source_location> when it's available, and it also requires making the signature in reflection::source_location::current from constexpr to consteval. This was tested to have success when I incorporated my own patch of ut.hpp with my own test compiled in MSVC.

Does this approach sound reasonable? I can open a PR if needed.

@sam20908
Copy link
Contributor

It looks like this issue is solved by 76e2f56. This issue can be closed.

@claremacrae
Copy link
Contributor Author

claremacrae commented Jun 20, 2021

Hi, thanks for looking this - much appreciated!

Can someone please say why the failing test in the godbolt link above is still failing - it downloads the latest version of the header from here, so if this bug were fixed, I would have thought that the 2nd test in that code would be passing now....

Here's the link again:
https://godbolt.org/z/13Y7Wq1r7

@claremacrae
Copy link
Contributor Author

claremacrae commented Aug 18, 2021

@krzysztof-jusiak Hi Kris, in case you haven't seen it already, this issue isn't fixed - the godbolt link in the issue description and in the comment above still fails to compile... the error is still present...

Please could you re-open this ticket, or perhaps provide a workaround? Many thanks.

/CC @sam20908

@kris-jusiak
Copy link
Contributor

oh, sorry, I didn't noice, thank you for pointing it out, repopened now

@kris-jusiak kris-jusiak reopened this Aug 18, 2021
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

No branches or pull requests

3 participants