GUACAMOLE-662: Log test output in TAP format.
This commit is contained in:
parent
d7118fda70
commit
ca4009c982
@ -39,15 +39,23 @@
|
||||
|
||||
use strict;
|
||||
|
||||
# Parse all test declarations from given file
|
||||
my $num_tests = 0;
|
||||
my %test_suites = ();
|
||||
|
||||
# Parse all test declarations from given file
|
||||
while (<>) {
|
||||
if ((my $suite_name, my $test_name) = m/^void\s+test_(\w+)__(\w+)/) {
|
||||
$num_tests++;
|
||||
$test_suites{$suite_name} //= ();
|
||||
push @{$test_suites{$suite_name}}, $test_name;
|
||||
}
|
||||
}
|
||||
|
||||
# Bail out if there's nothing to write
|
||||
if ($num_tests == 0) {
|
||||
die "No unit tests... :(\n";
|
||||
}
|
||||
|
||||
#
|
||||
# Common test runner header
|
||||
#
|
||||
@ -73,7 +81,44 @@ print <<'END';
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <CUnit/Basic.h>
|
||||
#include <CUnit/TestRun.h>
|
||||
|
||||
/**
|
||||
* The current test number, as required by the TAP format. This value is
|
||||
* automatically incremented by tap_log_test_completed() after each test is
|
||||
* run.
|
||||
*/
|
||||
int tap_test_number = 1;
|
||||
|
||||
/**
|
||||
* Logs the status of a CUnit test which just completed. This implementation
|
||||
* logs test completion in TAP format.
|
||||
*
|
||||
* @param test
|
||||
* The CUnit test which just completed.
|
||||
*
|
||||
* @param suite
|
||||
* The CUnit test suite associated with the test.
|
||||
*
|
||||
* @param failure
|
||||
* The head element of the test failure list, or NULL if the test passed.
|
||||
*/
|
||||
static void tap_log_test_completed(const CU_pTest test,
|
||||
const CU_pSuite suite, const CU_pFailureRecord failure) {
|
||||
|
||||
/* Log success/failure in TAP format */
|
||||
if (failure == NULL)
|
||||
printf("ok %i - [%s] %s: OK\n",
|
||||
tap_test_number, suite->pName, test->pName);
|
||||
else
|
||||
printf("not ok %i - [%s] %s: Assertion failed on %s:%i: %s\n",
|
||||
tap_test_number, suite->pName, test->pName,
|
||||
failure->strFileName, failure->uiLineNumber,
|
||||
failure->strCondition);
|
||||
|
||||
tap_test_number++;
|
||||
|
||||
}
|
||||
END
|
||||
|
||||
#
|
||||
@ -132,9 +177,12 @@ while ((my $suite_name, my $test_names) = each (%test_suites)) {
|
||||
|
||||
print <<"END";
|
||||
|
||||
/* Write TAP header */
|
||||
printf("1..$num_tests\\n");
|
||||
|
||||
/* Run all tests in all suites */
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
CU_set_test_complete_handler(tap_log_test_completed);
|
||||
CU_run_all_tests();
|
||||
|
||||
cleanup:
|
||||
/* Tests complete */
|
||||
|
Loading…
Reference in New Issue
Block a user