3#include <argparse/argparse.hpp>
7#include "formatters/junit_xml.hpp"
15inline std::string file_name(std::string_view path) {
16 std::string_view file = path;
17 for (
size_t i = 0; i < path.size(); ++i) {
22 return std::string{file};
25inline Runner parse(
int argc,
char**
const argv) {
26 std::filesystem::path executable_path = argv[0];
27 std::string executable_name = executable_path.filename().string();
28 argparse::ArgumentParser program{executable_name};
30 program.add_argument(
"-f",
"--format")
31 .default_value(std::string{
"p"})
32 .choices(
"progress",
"p",
"tap",
"t",
"detail",
"d",
"junit",
"j")
34 .help(
"set the output format");
36 program.add_argument(
"--output-junit").help(
"output JUnit XML to the specified file").default_value(std::string{});
37 program.add_argument(
"--verbose").help(
"increase output verbosity").flag();
40 program.parse_args(argc, argv);
41 }
catch (
const std::runtime_error& err) {
42 std::cerr << err.what() << std::endl;
47 auto format_string = program.get<std::string>(
"--format");
48 std::shared_ptr<Formatters::BaseFormatter> formatter;
49 if (format_string ==
"d" || format_string ==
"detail" || program[
"--verbose"] ==
true) {
50 formatter = std::make_shared<Formatters::Verbose>();
51 }
else if (format_string ==
"p" || format_string ==
"progress") {
52 formatter = std::make_shared<Formatters::Progress>();
53 }
else if (format_string ==
"t" || format_string ==
"tap") {
54 formatter = std::make_shared<Formatters::TAP>();
55 }
else if (format_string ==
"j" || format_string ==
"junit") {
56 formatter = std::make_shared<Formatters::JUnitXML>();
58 std::cerr <<
"Unrecognized format type" << std::endl;
62 auto junit_output_filepath = program.get<std::string>(
"--output-junit");
63 if (!junit_output_filepath.empty()) {
65 auto* file_stream =
new std::ofstream(junit_output_filepath);
66 auto junit_output = std::make_shared<Formatters::JUnitXML>(*file_stream,
false);
67 return Runner{formatter, junit_output};
A collection of Descriptions that are run in sequence.
Definition runner.hpp:16