| 1 | #include <cgreen/cgreen.h> |
| 2 | |
| 3 | #include "discoverer.h" |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | Describe(Discoverer); |
| 8 | BeforeEach(Discoverer) {} |
| 9 | AfterEach(Discoverer) {} |
| 10 | |
| 11 | static bool verbose = false; |
| 12 | |
| 13 | static int count_tests_in(const char *filename) { |
| 14 | char command[1000]; |
| 15 | sprintf(command, "/usr/bin/nm '%s'", filename); |
| 16 | FILE *nm_output = popen(command, "r"); |
| 17 | char line[10000]; |
| 18 | int count = 0; |
| 19 | while (fgets(line, sizeof(line), nm_output) != 0) { |
| 20 | if (strstr(line, CGREEN_SPEC_PREFIX CGREEN_SEPARATOR) != NULL) |
| 21 | count++; |
| 22 | } |
| 23 | return count; |
| 24 | } |
| 25 | |
| 26 | Ensure(Discoverer, reads_a_library_and_finds_the_tests) { |
| 27 | char filename[] = "libdiscoverer_unit_tests.so"; |
| 28 | CgreenVector *tests = discover_tests_in(filename, verbose); |
| 29 | assert_that(cgreen_vector_size(tests), is_equal_to(count_tests_in(filename))); |
| 30 | } |
| 31 | |
| 32 | TestSuite *discoverer_acceptance_tests(void) { |
| 33 | TestSuite *suite = create_test_suite(); |
| 34 | add_test_with_context(suite, Discoverer, reads_a_library_and_finds_the_tests); |
| 35 | return suite; |
| 36 | } |