You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2019/01/07 00:43:35 UTC
[4/7] guacamole-server git commit: GUACAMOLE-662: Log test output in
TAP format.
GUACAMOLE-662: Log test output in TAP format.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-server/commit/ca4009c9
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-server/tree/ca4009c9
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-server/diff/ca4009c9
Branch: refs/heads/master
Commit: ca4009c9824b26af9c2785fc847dfe7f9f14bc1d
Parents: d7118fd
Author: Michael Jumper <mj...@apache.org>
Authored: Tue Nov 13 19:55:06 2018 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Sat Nov 17 12:41:48 2018 -0800
----------------------------------------------------------------------
util/generate-test-runner.pl | 56 ++++++++++++++++++++++++++++++++++++---
1 file changed, 52 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/ca4009c9/util/generate-test-runner.pl
----------------------------------------------------------------------
diff --git a/util/generate-test-runner.pl b/util/generate-test-runner.pl
index c32ec0c..a121a07 100755
--- a/util/generate-test-runner.pl
+++ b/util/generate-test-runner.pl
@@ -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 */