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: support running single file in fizzy-spectests #525

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion test/smoketests/spectests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION "PASSED 32, FAILED 0, SKIPPED 3"
)

add_test(
NAME fizzy/smoketests/spectests/default/smoketest.json
COMMAND fizzy-spectests ${CMAKE_CURRENT_LIST_DIR}/default/smoketest.json
)
set_tests_properties(
fizzy/smoketests/spectests/default
PROPERTIES
PASS_REGULAR_EXPRESSION "PASSED 32, FAILED 0, SKIPPED 3"
)

add_test(
NAME fizzy/smoketests/spectests/skipvalidation
COMMAND fizzy-spectests ${CMAKE_CURRENT_LIST_DIR}/default --skip-validation
Expand Down Expand Up @@ -79,7 +89,7 @@ add_test(
set_tests_properties(
fizzy/smoketests/spectests/cli-missing-dir-arg
PROPERTIES
PASS_REGULAR_EXPRESSION "Missing DIR argument"
PASS_REGULAR_EXPRESSION "Missing PATH argument"
)

add_test(
Expand Down
32 changes: 23 additions & 9 deletions test/spectests/spectests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,21 @@ class test_runner
std::string m_current_test_type;
};

void log_total(const fs::path& path, const test_results& res)
{
std::cout << "TOTAL " << (res.passed + res.failed + res.skipped) << " tests ran from " << path
<< ".\n PASSED " << res.passed << ", FAILED " << res.failed << ", SKIPPED "
<< res.skipped << ".\n";
}

bool run_tests_from_file(const fs::path& path, const test_settings& settings)
{
const auto res = test_runner{settings}.run_from_file(path);

log_total(path, res);
return res.failed == 0;
}

bool run_tests_from_dir(const fs::path& path, const test_settings& settings)
{
std::vector<fs::path> files;
Expand All @@ -688,10 +703,7 @@ bool run_tests_from_dir(const fs::path& path, const test_settings& settings)
total.skipped += res.skipped;
}

std::cout << "TOTAL " << (total.passed + total.failed + total.skipped) << " tests ran from "
<< path << ".\n PASSED " << total.passed << ", FAILED " << total.failed
<< ", SKIPPED " << total.skipped << ".\n";

log_total(path, total);
return total.failed == 0;
}

Expand All @@ -701,7 +713,7 @@ int main(int argc, char** argv)
{
try
{
std::string dir;
std::string target;
test_settings settings;

for (auto i = 1; i < argc; ++i)
Expand All @@ -723,16 +735,18 @@ int main(int argc, char** argv)
}
}
else
dir = argv[i];
target = argv[i];
}

if (dir.empty())
if (target.empty())
{
std::cerr << "Missing DIR argument\n";
std::cerr << "Missing PATH argument\n";
return -1;
}

const bool res = run_tests_from_dir(dir, settings);
const fs::path path = target;
const bool res = fs::is_directory(path) ? run_tests_from_dir(path, settings) :
run_tests_from_file(path, settings);
return res ? 0 : 1;
}
catch (const std::exception& ex)
Expand Down