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

How to override file_line_to_stream? #369

Closed
UnePierre opened this issue May 9, 2020 · 4 comments
Closed

How to override file_line_to_stream? #369

UnePierre opened this issue May 9, 2020 · 4 comments

Comments

@UnePierre
Copy link
Contributor

My IDE (IAR EWARM) needs some weird tags ("\x01<SRCREF file="..." line=... \x01>", "\x01</SRCREF\x01>") around the file and line to produce a clickable link from console output.

I could write my own reporter, which would be a clone of the console reporter (which is fine!), just to add these tags into the output stream in file_line_to_stream() --- or this interface could be virtual and possible to override in a derived reporter implementation.

Overriding the remainder, DOCTEST_INTERNAL_ERROR, to produce a clickable link is rather easy, and superfluous. Have I overlooked more ways in which doctest prints location information?

@onqtam
Copy link
Member

onqtam commented May 9, 2020

Making file_line_to_stream() a member instead of a free function and also virtual seems like a good idea - it doesn't even need to be added to the base class API for reporters. I'll do that.

As for DOCTEST_INTERNAL_ERROR - would you like for me to add #ifndef DOCTEST_INTERNAL_ERROR & #endif around it so that you can more easily override it?

@UnePierre
Copy link
Contributor Author

Thanks.

And: yes, please, also: thanks!

You're doing a very good job here!

@onqtam
Copy link
Member

onqtam commented May 11, 2020

pushed in the dev branch

@UnePierre
Copy link
Contributor Author

Works like a charm, at least for me.

BTW, here is the overriding for IAR EWARM, running doctest-enabled simulation in cspybat as a post-build action:

struct EWARM_Reporter : public doctest::ConsoleReporter
{
    EWARM_Reporter(const doctest::ContextOptions& in)
        : doctest::ConsoleReporter(in) { }

    virtual void file_line_to_stream(const char* file, int line, const char* tail = "") override
    {
        using namespace doctest;
        s << Color::LightGrey
          << "\x01<SRCREF file=\"" << file << "\" line=" << line << "\x01>"
          << skipPathFromFilename(file) << (opt.gnu_file_line ? ":" : "(")
          << (opt.no_line_numbers ? 0 : line) // 0 or the real num depending on the option
          << (opt.gnu_file_line ? ":" : "):")
          << "\x01</SRCREF\x01>"
          << tail;
    }
};

REGISTER_REPORTER("ewarm", 1, EWARM_Reporter); // "1" is the priority - used for ordering when multiple reporters/listeners are used

I might add some knowledge how to pass-in command-line arguments, and how to access the passed/failed status upon request.

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

2 participants