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 command line tools --- proposal #175

Open
elshize opened this issue Apr 17, 2019 · 0 comments
Open

Test command line tools --- proposal #175

elshize opened this issue Apr 17, 2019 · 0 comments
Assignees

Comments

@elshize
Copy link
Member

elshize commented Apr 17, 2019

Proposal

This is one idea I had that doesn't involve some crazy complicated stuff in C++.

Basically, we have a hidden flag --print-arguments that doesn't show up in the help. We always have this pattern:

int main(int argc, char** argv)
{
    if (argc > 1 and argv[1]) {
        print_out(args(argc, argv));
    } else {
        std::apply(do_work, args(argc, argv));
    }
}

where print_out simply prints out the arguments so we can verify them in testing; and do_work is the entry function of the program, args is a program-specific function where you do all the CLI stuff and return a tuple to apply to the do_work function (names are just examples).

So now we can verify that we pass the right values by running a simple python script and compare the output.

Ideally, do_work should have its own integration test but that might be tricky sometimes. First, it must be separated in a header. In that case, some things would be compiled twice, which is an awful idea for things like queries.

There is one solution that might be a bit annoying. We'd have three files:

  1. program.hpp
  2. program.cpp
  3. program_entry.cpp

The last one would be something like this:

#include program.hpp

int main(int argc, char** argv) {
    std::apply(do_work, args(argc, argv));
}

This is not ideal, but actually this would allow to directly test args from Catch.

Any thoughts? Other ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant