Skip to content
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
13 changes: 13 additions & 0 deletions src/lang/test/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ auto test_run(int argc, char **argv) -> int {
std::cout << "TAP version 14\n";
std::cout << "1.." << selected.size() << "\n";

// A test binary exists to run tests, so selecting none exits with failure on
// purpose. An empty run means either broken registration or a filter that
// matches nothing, neither of which may pass as a green suite
if (selected.empty()) {
if (needle.empty()) {
print_diagnostic("no tests were registered");
} else {
print_diagnostic("no tests matched the filter: " + std::string{needle});
}

return EXIT_FAILURE;
}

std::size_t number{0};
std::size_t passed{0};
std::size_t failed{0};
Expand Down
5 changes: 5 additions & 0 deletions test/test/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ add_executable(sourcemeta_core_test_dynamic test_dynamic.cc)
target_link_libraries(sourcemeta_core_test_dynamic
PRIVATE sourcemeta::core::test sourcemeta::core::test_main)

add_executable(sourcemeta_core_test_empty test_empty.cc)
target_link_libraries(sourcemeta_core_test_empty
PRIVATE sourcemeta::core::test sourcemeta::core::test_main)

# The framework's own command line is exercised through the script runner that
# this module ships, so the language is proven against the framework hosting it
macro(add_framework_test name binary)
Expand All @@ -45,3 +49,4 @@ add_framework_test(filter_short sourcemeta_core_test_filter)
add_framework_test(filter_none sourcemeta_core_test_filter)
add_framework_test(fixture sourcemeta_core_test_fixture)
add_framework_test(dynamic sourcemeta_core_test_dynamic)
add_framework_test(empty sourcemeta_core_test_empty)
1 change: 1 addition & 0 deletions test/test/framework/test_empty.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <sourcemeta/core/test.h>
7 changes: 7 additions & 0 deletions test/test/framework/test_empty.clitest
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RUN STDIN /dev/null IN . INTO result.txt EXPECTING 1
WRITE expected.txt UNTIL EXPECTED
1> TAP version 14
1> 1..0
1> # no tests were registered
EXPECTED
COMPARE result.txt AGAINST expected.txt
4 changes: 2 additions & 2 deletions test/test/framework/test_filter_none.clitest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RUN --filter nonexistent STDIN /dev/null IN . INTO result.txt EXPECTING 0
RUN --filter nonexistent STDIN /dev/null IN . INTO result.txt EXPECTING 1
WRITE expected.txt UNTIL EXPECTED
1> TAP version 14
1> 1..0
1> # 0 passed, 0 failed
1> # no tests matched the filter: nonexistent
EXPECTED
COMPARE result.txt AGAINST expected.txt
Loading