Browse Source

Update to the latest tinytest version

This cleans up some whitespace consistency issues and, more
importantly, gives you the ability to skip tests from the command
line.
Nick Mathewson 13 years ago
parent
commit
608d1614b9
3 changed files with 26 additions and 15 deletions
  1. 19 8
      src/test/tinytest.c
  2. 1 1
      src/test/tinytest.h
  3. 6 6
      src/test/tinytest_macros.h

+ 19 - 8
src/test/tinytest.c

@@ -1,4 +1,4 @@
-/* tinytest.c -- Copyright 2009 Nick Mathewson
+/* tinytest.c -- Copyright 2009-2010 Nick Mathewson
  *
  *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * modification, are permitted provided that the following conditions
@@ -40,6 +40,9 @@
 #define __attribute__(x)
 #define __attribute__(x)
 #endif
 #endif
 
 
+#ifdef TINYTEST_LOCAL
+#include "tinytest_local.h"
+#endif
 #include "tinytest.h"
 #include "tinytest.h"
 #include "tinytest_macros.h"
 #include "tinytest_macros.h"
 
 
@@ -58,7 +61,7 @@ const char *verbosity_flag = "";
 enum outcome { SKIP=2, OK=1, FAIL=0 };
 enum outcome { SKIP=2, OK=1, FAIL=0 };
 static enum outcome cur_test_outcome = 0;
 static enum outcome cur_test_outcome = 0;
 const char *cur_test_prefix = NULL; /**< prefix of the current test group */
 const char *cur_test_prefix = NULL; /**< prefix of the current test group */
-/** Name of the  current test, if we haven't logged is yet. Used for --quiet */
+/** Name of the current test, if we haven't logged is yet. Used for --quiet */
 const char *cur_test_name = NULL;
 const char *cur_test_name = NULL;
 
 
 #ifdef WIN32
 #ifdef WIN32
@@ -76,7 +79,7 @@ _testcase_run_bare(const struct testcase_t *testcase)
 	int outcome;
 	int outcome;
 	if (testcase->setup) {
 	if (testcase->setup) {
 		env = testcase->setup->setup_fn(testcase);
 		env = testcase->setup->setup_fn(testcase);
-                if (!env)
+		if (!env)
 			return FAIL;
 			return FAIL;
 		else if (env == (void*)TT_SKIP)
 		else if (env == (void*)TT_SKIP)
 			return SKIP;
 			return SKIP;
@@ -149,7 +152,7 @@ _testcase_run_forked(const struct testgroup_t *group,
 #else
 #else
 	int outcome_pipe[2];
 	int outcome_pipe[2];
 	pid_t pid;
 	pid_t pid;
-        (void)group;
+	(void)group;
 
 
 	if (pipe(outcome_pipe))
 	if (pipe(outcome_pipe))
 		perror("opening pipe");
 		perror("opening pipe");
@@ -165,7 +168,7 @@ _testcase_run_forked(const struct testgroup_t *group,
 		test_r = _testcase_run_bare(testcase);
 		test_r = _testcase_run_bare(testcase);
 		assert(0<=(int)test_r && (int)test_r<=2);
 		assert(0<=(int)test_r && (int)test_r<=2);
 		b[0] = "NYS"[test_r];
 		b[0] = "NYS"[test_r];
-	        write_r = (int)write(outcome_pipe[1], b, 1);
+		write_r = (int)write(outcome_pipe[1], b, 1);
 		if (write_r != 1) {
 		if (write_r != 1) {
 			perror("write outcome to pipe");
 			perror("write outcome to pipe");
 			exit(1);
 			exit(1);
@@ -217,7 +220,7 @@ testcase_run_one(const struct testgroup_t *group,
 	if ((testcase->flags & TT_FORK) && !(opt_forked||opt_nofork)) {
 	if ((testcase->flags & TT_FORK) && !(opt_forked||opt_nofork)) {
 		outcome = _testcase_run_forked(group, testcase);
 		outcome = _testcase_run_forked(group, testcase);
 	} else {
 	} else {
-		outcome  = _testcase_run_bare(testcase);
+		outcome = _testcase_run_bare(testcase);
 	}
 	}
 
 
 	if (outcome == OK) {
 	if (outcome == OK) {
@@ -270,6 +273,7 @@ usage(struct testgroup_t *groups, int list_groups)
 {
 {
 	puts("Options are: [--verbose|--quiet|--terse] [--no-fork]");
 	puts("Options are: [--verbose|--quiet|--terse] [--no-fork]");
 	puts("  Specify tests by name, or using a prefix ending with '..'");
 	puts("  Specify tests by name, or using a prefix ending with '..'");
+	puts("  To skip a test, list give its name prefixed with a colon.");
 	puts("  Use --list-tests for a list of tests.");
 	puts("  Use --list-tests for a list of tests.");
 	if (list_groups) {
 	if (list_groups) {
 		puts("Known tests are:");
 		puts("Known tests are:");
@@ -310,8 +314,15 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
 				return -1;
 				return -1;
 			}
 			}
 		} else {
 		} else {
-			++n;
-			if (!_tinytest_set_flag(groups, v[i], _TT_ENABLED)) {
+			const char *test = v[i];
+			int flag = _TT_ENABLED;
+			if (test[0] == ':') {
+				++test;
+				flag = TT_SKIP;
+			} else {
+				++n;
+			}
+			if (!_tinytest_set_flag(groups, test, flag)) {
 				printf("No such test as %s!\n", v[i]);
 				printf("No such test as %s!\n", v[i]);
 				return -1;
 				return -1;
 			}
 			}

+ 1 - 1
src/test/tinytest.h

@@ -1,4 +1,4 @@
-/* tinytest.h -- Copyright 2009 Nick Mathewson
+/* tinytest.h -- Copyright 2009-2010 Nick Mathewson
  *
  *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * modification, are permitted provided that the following conditions

+ 6 - 6
src/test/tinytest_macros.h

@@ -1,4 +1,4 @@
-/* tinytest_macros.h -- Copyright 2009 Nick Mathewson
+/* tinytest_macros.h -- Copyright 2009-2010 Nick Mathewson
  *
  *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * modification, are permitted provided that the following conditions
@@ -28,7 +28,7 @@
 
 
 /* Helpers for defining statement-like macros */
 /* Helpers for defining statement-like macros */
 #define TT_STMT_BEGIN do {
 #define TT_STMT_BEGIN do {
-#define TT_STMT_END } while(0)
+#define TT_STMT_END } while (0)
 
 
 /* Redefine this if your test functions want to abort with something besides
 /* Redefine this if your test functions want to abort with something besides
  * "goto end;" */
  * "goto end;" */
@@ -45,7 +45,7 @@
 	TT_STMT_END
 	TT_STMT_END
 #endif
 #endif
 
 
-/* Announce a failure.  Args are parenthesized printf args. */
+/* Announce a failure. Args are parenthesized printf args. */
 #define TT_GRIPE(args) TT_DECLARE("FAIL", args)
 #define TT_GRIPE(args) TT_DECLARE("FAIL", args)
 
 
 /* Announce a non-failure if we're verbose. */
 /* Announce a non-failure if we're verbose. */
@@ -80,7 +80,7 @@
 #define tt_fail() TT_FAIL(("%s", "(Failed.)"))
 #define tt_fail() TT_FAIL(("%s", "(Failed.)"))
 
 
 /* End the current test, and indicate we are skipping it. */
 /* End the current test, and indicate we are skipping it. */
-#define tt_skip()                               \
+#define tt_skip()						\
 	TT_STMT_BEGIN						\
 	TT_STMT_BEGIN						\
 	_tinytest_set_test_skipped();				\
 	_tinytest_set_test_skipped();				\
 	TT_EXIT_TEST_FUNCTION;					\
 	TT_EXIT_TEST_FUNCTION;					\
@@ -111,7 +111,7 @@
 #define tt_assert(b) tt_assert_msg((b), "assert("#b")")
 #define tt_assert(b) tt_assert_msg((b), "assert("#b")")
 
 
 #define tt_assert_test_fmt_type(a,b,str_test,type,test,printf_type,printf_fmt, \
 #define tt_assert_test_fmt_type(a,b,str_test,type,test,printf_type,printf_fmt, \
-                                setup_block,cleanup_block)              \
+				setup_block,cleanup_block)		\
 	TT_STMT_BEGIN							\
 	TT_STMT_BEGIN							\
 	type _val1 = (type)(a);						\
 	type _val1 = (type)(a);						\
 	type _val2 = (type)(b);						\
 	type _val2 = (type)(b);						\
@@ -126,7 +126,7 @@
 		_value = _val2;						\
 		_value = _val2;						\
 		setup_block;						\
 		setup_block;						\
 		_print2 = _print;					\
 		_print2 = _print;					\
-		TT_DECLARE(_tt_status?"  OK":"FAIL",			\
+		TT_DECLARE(_tt_status?"	 OK":"FAIL",			\
 			   ("assert(%s): "printf_fmt" vs "printf_fmt,	\
 			   ("assert(%s): "printf_fmt" vs "printf_fmt,	\
 			    str_test, _print1, _print2));		\
 			    str_test, _print1, _print2));		\
 		_print = _print1;					\
 		_print = _print1;					\