test/driver/TestDriver.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "TestDriver.h" | ||
| 4 | |||
| 5 | #include "util/CommonUtil.h" | ||
| 6 | |||
| 7 | // GCOV_EXCL_START | ||
| 8 | namespace spice::testing { | ||
| 9 | |||
| 10 | TestDriverCliOptions testDriverCliOptions; | ||
| 11 | |||
| 12 | − | void TestDriver::createInterface() { | |
| 13 | // Allow positional args | ||
| 14 | − | app.allow_non_standard_option_names(); | |
| 15 | − | app.positionals_at_end(); | |
| 16 | − | app.require_subcommand(0); | |
| 17 | − | app.allow_extras(false); | |
| 18 | − | app.footer("(c) Marc Auberer 2021-2026"); | |
| 19 | |||
| 20 | // Add version flag | ||
| 21 | − | app.set_version_flag("--version,-v", compiler::CommonUtil::buildVersionInfo()); | |
| 22 | − | } | |
| 23 | |||
| 24 | − | void TestDriver::addOptions() { | |
| 25 | // --update-refs | ||
| 26 | CLI::Option *updateRefsOpt = | ||
| 27 | − | app.add_flag<bool>("--update-refs", testDriverCliOptions.updateRefs, "Update test reference files"); | |
| 28 | // --run-benchmarks | ||
| 29 | − | app.add_flag<bool>("--run-benchmarks", testDriverCliOptions.runBenchmarks, "Also run benchmarks and check baseline values"); | |
| 30 | // --leak-detection | ||
| 31 | − | app.add_flag<bool>("--leak-detection", testDriverCliOptions.enableLeakDetection, | |
| 32 | − | "Use Valgrind on tests to detect memory leaks"); | |
| 33 | // --is-github-actions | ||
| 34 | − | app.add_flag<bool>("--is-github-actions", testDriverCliOptions.isGitHubActions, | |
| 35 | − | "Skip tests that are not supported to run on GitHub Actions"); | |
| 36 | // --skip-sanitizer-tests | ||
| 37 | − | app.add_flag<bool>("--skip-sanitizer-tests", testDriverCliOptions.skipSanitizerTests, | |
| 38 | − | "Skip tests that exercise Spice language sanitizers (e.g. ASAN, TSAN, MSAN, TYSAN)"); | |
| 39 | // --verbose | ||
| 40 | − | app.add_flag<bool>("--verbose", testDriverCliOptions.isVerbose, "Print debug output for the test runner"); | |
| 41 | // --coverage | ||
| 42 | CLI::Option *coverageOpt = | ||
| 43 | − | app.add_flag<bool>("--coverage", testDriverCliOptions.enableCoverage, | |
| 44 | − | "Compile and run test programs with Spice code coverage instrumentation enabled, skipping all " | |
| 45 | "reference output comparisons (debug info and coverage counters change the generated code)"); | ||
| 46 | // Coverage mode never compares against (or writes) reference files, so combining it with --update-refs would silently | ||
| 47 | // overwrite tracked fixtures with coverage-instrumented, no-longer-comparable output. Reject the combination outright. | ||
| 48 | − | coverageOpt->excludes(updateRefsOpt); | |
| 49 | // --bootstrap | ||
| 50 | CLI::Option *bootstrapOpt = | ||
| 51 | − | app.add_flag<bool>("--bootstrap", testDriverCliOptions.bootstrapMode, | |
| 52 | − | "Build the bootstrap compiler with the host compiler first, then run the test cases against it"); | |
| 53 | // --bootstrap-compiler | ||
| 54 | − | CLI::Option *bootstrapCompilerOpt = app.add_option<std::string>( | |
| 55 | − | "--bootstrap-compiler", testDriverCliOptions.bootstrapCompilerPath, | |
| 56 | − | "Run the test cases against the given, already built bootstrap compiler executable (implies --bootstrap)"); | |
| 57 | // The reference files hold the output of the host compiler, so they must never be overwritten with bootstrap output. The | ||
| 58 | // coverage mode instruments the programs compiled by the host compiler, which the bootstrap mode does not compile at all. | ||
| 59 | − | bootstrapOpt->excludes(updateRefsOpt)->excludes(coverageOpt); | |
| 60 | − | bootstrapCompilerOpt->excludes(updateRefsOpt)->excludes(coverageOpt); | |
| 61 | − | } | |
| 62 | |||
| 63 | /** | ||
| 64 | * Start the parsing process | ||
| 65 | * | ||
| 66 | * @param argc Argument count | ||
| 67 | * @param argv Argument vector | ||
| 68 | * @return Return code | ||
| 69 | */ | ||
| 70 | − | int TestDriver::parse(int argc, char **argv) { | |
| 71 | try { | ||
| 72 | − | app.parse(argc, argv); | |
| 73 | − | if (!testDriverCliOptions.bootstrapCompilerPath.empty()) | |
| 74 | − | testDriverCliOptions.bootstrapMode = true; | |
| 75 | − | return 0; | |
| 76 | − | } catch (const CLI::ParseError &parseError) { | |
| 77 | − | return app.exit(parseError); | |
| 78 | − | } | |
| 79 | } | ||
| 80 | |||
| 81 | } // namespace spice::testing | ||
| 82 | |||
| 83 | // GCOV_EXCL_STOP | ||
| 84 |