Browse Source

const addition changes from brian, awfulhak.org

Rusty Russell 16 years ago
parent
commit
72c55b03e0
3 changed files with 27 additions and 26 deletions
  1. 12 11
      ccan/tap/tap.3
  2. 9 9
      ccan/tap/tap.c
  3. 6 6
      ccan/tap/tap.h

+ 12 - 11
ccan/tap/tap.3

@@ -16,9 +16,9 @@ their success or failure.
 .Ss PRINTF STRINGS
 .Ss PRINTF STRINGS
 In the descriptions that follow, for any function that takes as the
 In the descriptions that follow, for any function that takes as the
 last two parameters
 last two parameters
-.Dq Fa char * , Fa ...
+.Dq Fa const char * , Fa ...
 it can be assumed that the
 it can be assumed that the
-.Fa char *
+.Fa const char *
 is a
 is a
 .Fn printf
 .Fn printf
 -like format string, and the optional arguments are values to be placed
 -like format string, and the optional arguments are values to be placed
@@ -35,7 +35,7 @@ in that string.
 .Xc
 .Xc
 .It Xo
 .It Xo
 .Ft void
 .Ft void
-.Fn plan_skip_all "char *" "..."
+.Fn plan_skip_all "const char *" "..."
 .Xc
 .Xc
 .El
 .El
 .Pp
 .Pp
@@ -74,7 +74,7 @@ the tests.
 .Bl -tag -width indent
 .Bl -tag -width indent
 .It Xo
 .It Xo
 .Ft unsigned int
 .Ft unsigned int
-.Fn ok "expression" "char *" "..."
+.Fn ok "expression" "const char *" "..."
 .Xc
 .Xc
 .It Xo
 .It Xo
 .Ft unsigned int
 .Ft unsigned int
@@ -82,11 +82,11 @@ the tests.
 .Xc
 .Xc
 .It Xo
 .It Xo
 .Ft unsigned int
 .Ft unsigned int
-.Fn pass "char *" "..."
+.Fn pass "const char *" "..."
 .Xc
 .Xc
 .It Xo
 .It Xo
 .Ft unsigned int
 .Ft unsigned int
-.Fn fail "char *" "..."
+.Fn fail "const char *" "..."
 .Xc
 .Xc
 .El
 .El
 .Pp
 .Pp
@@ -161,10 +161,10 @@ These are synonyms for ok(1, ...) and ok(0, ...).
 .Bl -tag -width indent
 .Bl -tag -width indent
 .It Xo
 .It Xo
 .Ft void
 .Ft void
-.Fn skip "unsigned int" "char *" "..."
+.Fn skip "unsigned int" "const char *" "..."
 .Xc
 .Xc
 .It Xo
 .It Xo
-.Fn skip_if "expression" "unsigned int" "char *" "..."
+.Fn skip_if "expression" "unsigned int" "const char *" "..."
 .Xc
 .Xc
 .El
 .El
 .Pp
 .Pp
@@ -204,7 +204,7 @@ skip_if(getuid() != 0, 1, "because test only works as root") {
 .Bl -tag -width indent
 .Bl -tag -width indent
 .It Xo
 .It Xo
 .Ft void
 .Ft void
-.Fn todo_start "char *" "..."
+.Fn todo_start "const char *" "..."
 .Xc
 .Xc
 .It Xo
 .It Xo
 .Ft void
 .Ft void
@@ -261,8 +261,8 @@ yet to fix, but want to put tests in your testing script
 .Ss DIAGNOSTIC OUTPUT
 .Ss DIAGNOSTIC OUTPUT
 .Bl -tag -width indent
 .Bl -tag -width indent
 .It Xo
 .It Xo
-.Fr void
-.Fn diag "char *" "..."
+.Fr int
+.Fn diag "const char *" "..."
 .Xc
 .Xc
 .El
 .El
 .Pp
 .Pp
@@ -273,6 +273,7 @@ It ensures that the output will not be considered by the TAP test harness.
 adds the necessary trailing
 adds the necessary trailing
 .Dq \en
 .Dq \en
 for you.
 for you.
+It returns the number of characters written.
 .Bd -literal -offset indent
 .Bd -literal -offset indent
 diag("Expected return code 0, got return code %d", rcode);
 diag("Expected return code 0, got return code %d", rcode);
 .Ed
 .Ed

+ 9 - 9
ccan/tap/tap.c

@@ -42,7 +42,7 @@ static unsigned int test_count = 0; /* Number of tests that have been run */
 static unsigned int e_tests = 0; /* Expected number of tests to run */
 static unsigned int e_tests = 0; /* Expected number of tests to run */
 static unsigned int failures = 0; /* Number of tests that failed */
 static unsigned int failures = 0; /* Number of tests that failed */
 static char *todo_msg = NULL;
 static char *todo_msg = NULL;
-static char *todo_msg_fixed = "libtap malloc issue";
+static const char *todo_msg_fixed = "libtap malloc issue";
 static int todo = 0;
 static int todo = 0;
 static int test_died = 0;
 static int test_died = 0;
 static int test_pid;
 static int test_pid;
@@ -68,7 +68,7 @@ _expected_tests(unsigned int tests)
 }
 }
 
 
 static void
 static void
-diagv(char *fmt, va_list ap)
+diagv(const char *fmt, va_list ap)
 {
 {
 	fputs("# ", stdout);
 	fputs("# ", stdout);
 	vfprintf(stdout, fmt, ap);
 	vfprintf(stdout, fmt, ap);
@@ -76,7 +76,7 @@ diagv(char *fmt, va_list ap)
 }
 }
 
 
 static void
 static void
-_diag(char *fmt, ...)
+_diag(const char *fmt, ...)
 {
 {
 	va_list ap;
 	va_list ap;
 	va_start(ap, fmt);
 	va_start(ap, fmt);
@@ -92,8 +92,8 @@ _diag(char *fmt, ...)
  * test_comment -- a comment to print afterwards, may be NULL
  * test_comment -- a comment to print afterwards, may be NULL
  */
  */
 unsigned int
 unsigned int
-_gen_result(int ok, const char *func, char *file, unsigned int line, 
-	    char *test_name, ...)
+_gen_result(int ok, const char *func, const char *file, unsigned int line, 
+	    const char *test_name, ...)
 {
 {
 	va_list ap;
 	va_list ap;
 	char *local_test_name = NULL;
 	char *local_test_name = NULL;
@@ -293,7 +293,7 @@ plan_no_plan(void)
  * Note that the plan is to skip all tests
  * Note that the plan is to skip all tests
  */
  */
 void
 void
-plan_skip_all(char *reason)
+plan_skip_all(const char *reason)
 {
 {
 
 
 	LOCK;
 	LOCK;
@@ -345,7 +345,7 @@ plan_tests(unsigned int tests)
 }
 }
 
 
 void
 void
-diag(char *fmt, ...)
+diag(const char *fmt, ...)
 {
 {
 	va_list ap;
 	va_list ap;
 
 
@@ -359,7 +359,7 @@ diag(char *fmt, ...)
 }
 }
 
 
 void
 void
-skip(unsigned int n, char *fmt, ...)
+skip(unsigned int n, const char *fmt, ...)
 {
 {
 	va_list ap;
 	va_list ap;
 	char *skip_msg;
 	char *skip_msg;
@@ -384,7 +384,7 @@ skip(unsigned int n, char *fmt, ...)
 }
 }
 
 
 void
 void
-todo_start(char *fmt, ...)
+todo_start(const char *fmt, ...)
 {
 {
 	va_list ap;
 	va_list ap;
 
 

+ 6 - 6
ccan/tap/tap.h

@@ -124,8 +124,8 @@ void plan_tests(unsigned int tests);
 #endif
 #endif
 #endif
 #endif
 
 
-unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...)
-	PRINTF_ATTRIBUTE(5, 6);
+unsigned int _gen_result(int, const char *, const char *, unsigned int,
+   const char *, ...) PRINTF_ATTRIBUTE(5, 6);
 
 
 /**
 /**
  * diag - print a diagnostic message (use instead of printf/fprintf)
  * diag - print a diagnostic message (use instead of printf/fprintf)
@@ -137,7 +137,7 @@ unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...)
  * Example:
  * Example:
  *	diag("Now running complex tests");
  *	diag("Now running complex tests");
  */
  */
-void diag(char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
+void diag(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
 
 
 /**
 /**
  * skip - print a diagnostic message (use instead of printf/fprintf)
  * skip - print a diagnostic message (use instead of printf/fprintf)
@@ -160,7 +160,7 @@ void diag(char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
  *	skip(1, "Don't have SOME_FEATURE");
  *	skip(1, "Don't have SOME_FEATURE");
  *	#endif
  *	#endif
  */
  */
-void skip(unsigned int n, char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
+void skip(unsigned int n, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
 
 
 /**
 /**
  * todo_start - mark tests that you expect to fail.
  * todo_start - mark tests that you expect to fail.
@@ -185,7 +185,7 @@ void skip(unsigned int n, char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
  *	ok(dwim(), "Did what the user wanted");
  *	ok(dwim(), "Did what the user wanted");
  *	todo_end();
  *	todo_end();
  */
  */
-void todo_start(char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
+void todo_start(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
 
 
 /**
 /**
  * todo_end - end of tests you expect to fail.
  * todo_end - end of tests you expect to fail.
@@ -241,6 +241,6 @@ void plan_no_plan(void);
  *	}
  *	}
  *	plan_tests(13);
  *	plan_tests(13);
  */
  */
-void plan_skip_all(char *reason);
+void plan_skip_all(const char *reason);
 
 
 #endif /* C99 or gcc */
 #endif /* C99 or gcc */