summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-09-09 14:34:10 -0400
committerNick Mathewson <nickm@torproject.org>2010-09-09 14:34:10 -0400
commit608d1614b92045ffbaf44b6d4e93eae4036e7bac (patch)
treedd1793d3b92374d0ce3fa7dccdae8f43c6f8bc5f
parentc05c8dbd78f13bff79cda8fda1579aba51e30b0c (diff)
downloadtor-608d1614b92045ffbaf44b6d4e93eae4036e7bac.tar.gz
tor-608d1614b92045ffbaf44b6d4e93eae4036e7bac.zip
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.
-rw-r--r--src/test/tinytest.c27
-rw-r--r--src/test/tinytest.h2
-rw-r--r--src/test/tinytest_macros.h12
3 files changed, 26 insertions, 15 deletions
diff --git a/src/test/tinytest.c b/src/test/tinytest.c
index b453308121..11ffc2fe56 100644
--- a/src/test/tinytest.c
+++ b/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
* modification, are permitted provided that the following conditions
@@ -40,6 +40,9 @@
#define __attribute__(x)
#endif
+#ifdef TINYTEST_LOCAL
+#include "tinytest_local.h"
+#endif
#include "tinytest.h"
#include "tinytest_macros.h"
@@ -58,7 +61,7 @@ const char *verbosity_flag = "";
enum outcome { SKIP=2, OK=1, FAIL=0 };
static enum outcome cur_test_outcome = 0;
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;
#ifdef WIN32
@@ -76,7 +79,7 @@ _testcase_run_bare(const struct testcase_t *testcase)
int outcome;
if (testcase->setup) {
env = testcase->setup->setup_fn(testcase);
- if (!env)
+ if (!env)
return FAIL;
else if (env == (void*)TT_SKIP)
return SKIP;
@@ -149,7 +152,7 @@ _testcase_run_forked(const struct testgroup_t *group,
#else
int outcome_pipe[2];
pid_t pid;
- (void)group;
+ (void)group;
if (pipe(outcome_pipe))
perror("opening pipe");
@@ -165,7 +168,7 @@ _testcase_run_forked(const struct testgroup_t *group,
test_r = _testcase_run_bare(testcase);
assert(0<=(int)test_r && (int)test_r<=2);
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) {
perror("write outcome to pipe");
exit(1);
@@ -217,7 +220,7 @@ testcase_run_one(const struct testgroup_t *group,
if ((testcase->flags & TT_FORK) && !(opt_forked||opt_nofork)) {
outcome = _testcase_run_forked(group, testcase);
} else {
- outcome = _testcase_run_bare(testcase);
+ outcome = _testcase_run_bare(testcase);
}
if (outcome == OK) {
@@ -270,6 +273,7 @@ usage(struct testgroup_t *groups, int list_groups)
{
puts("Options are: [--verbose|--quiet|--terse] [--no-fork]");
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.");
if (list_groups) {
puts("Known tests are:");
@@ -310,8 +314,15 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
return -1;
}
} 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]);
return -1;
}
diff --git a/src/test/tinytest.h b/src/test/tinytest.h
index a0cb913138..cbe28b7f51 100644
--- a/src/test/tinytest.h
+++ b/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
* modification, are permitted provided that the following conditions
diff --git a/src/test/tinytest_macros.h b/src/test/tinytest_macros.h
index 48c1fbdfb8..a7fa64a824 100644
--- a/src/test/tinytest_macros.h
+++ b/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
* modification, are permitted provided that the following conditions
@@ -28,7 +28,7 @@
/* Helpers for defining statement-like macros */
#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
* "goto end;" */
@@ -45,7 +45,7 @@
TT_STMT_END
#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)
/* Announce a non-failure if we're verbose. */
@@ -80,7 +80,7 @@
#define tt_fail() TT_FAIL(("%s", "(Failed.)"))
/* End the current test, and indicate we are skipping it. */
-#define tt_skip() \
+#define tt_skip() \
TT_STMT_BEGIN \
_tinytest_set_test_skipped(); \
TT_EXIT_TEST_FUNCTION; \
@@ -111,7 +111,7 @@
#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, \
- setup_block,cleanup_block) \
+ setup_block,cleanup_block) \
TT_STMT_BEGIN \
type _val1 = (type)(a); \
type _val2 = (type)(b); \
@@ -126,7 +126,7 @@
_value = _val2; \
setup_block; \
_print2 = _print; \
- TT_DECLARE(_tt_status?" OK":"FAIL", \
+ TT_DECLARE(_tt_status?" OK":"FAIL", \
("assert(%s): "printf_fmt" vs "printf_fmt, \
str_test, _print1, _print2)); \
_print = _print1; \