X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flibpspp%2Fstr-test.c;h=f5897d72029c051ac03870aab63f62bb52b639ca;hb=4fd6d0378134d9653966258f44b0b0f8db15fbd5;hp=4e3867f4d50ee3c95d8786a14ed4a8b44d104def;hpb=c725a4f64718ef1ee4139c27c94b2eb6447b51b4;p=pspp diff --git a/tests/libpspp/str-test.c b/tests/libpspp/str-test.c index 4e3867f4d5..f5897d7202 100644 --- a/tests/libpspp/str-test.c +++ b/tests/libpspp/str-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2010, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,13 +18,9 @@ #include -#include #include #include -/* Currently running test. */ -static const char *test_name; - /* Exit with a failure code. (Place a breakpoint on this function while debugging.) */ static void @@ -37,7 +33,7 @@ static void check_26adic (unsigned long int number, const char *expected_string) { char string[8]; - str_format_26adic (number, string, sizeof string); + str_format_26adic (number, true, string, sizeof string); if (strcmp (string, expected_string)) { printf ("base-26 of %lu: expected \"%s\", got \"%s\"\n", @@ -47,7 +43,7 @@ check_26adic (unsigned long int number, const char *expected_string) } static void -test_str_format_26adic (void) +test_format_26adic (void) { check_26adic (0, ""); check_26adic (1, "A"); @@ -63,21 +59,54 @@ test_str_format_26adic (void) /* Main program. */ -/* Runs TEST_FUNCTION and prints a message about NAME. */ -static void -run_test (void (*test_function) (void), const char *name) -{ - test_name = name; - putchar ('.'); - fflush (stdout); - test_function (); -} +struct test + { + const char *name; + const char *description; + void (*function) (void); + }; + +static const struct test tests[] = + { + { + "format-26adic", + "format 26-adic strings", + test_format_26adic + } + }; + +enum { N_TESTS = sizeof tests / sizeof *tests }; int -main (void) +main (int argc, char *argv[]) { - run_test (test_str_format_26adic, "format 26-adic strings"); - putchar ('\n'); + int i; - return 0; + if (argc != 2) + { + fprintf (stderr, "exactly one argument required; use --help for help\n"); + return EXIT_FAILURE; + } + else if (!strcmp (argv[1], "--help")) + { + printf ("%s: test string library\n" + "usage: %s TEST-NAME\n" + "where TEST-NAME is one of the following:\n", + argv[0], argv[0]); + for (i = 0; i < N_TESTS; i++) + printf (" %s\n %s\n", tests[i].name, tests[i].description); + return 0; + } + else + { + for (i = 0; i < N_TESTS; i++) + if (!strcmp (argv[1], tests[i].name)) + { + tests[i].function (); + return 0; + } + + fprintf (stderr, "unknown test %s; use --help for help\n", argv[1]); + return EXIT_FAILURE; + } }