From: Ben Pfaff Date: Sat, 25 Sep 2010 22:17:10 +0000 (-0700) Subject: str: Convert tests to use Autotest. X-Git-Tag: v0.7.6~167 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06ac4ef9bba12ce73ec9855037bb6ab12cc51248;p=pspp-builds.git str: Convert tests to use Autotest. --- diff --git a/tests/automake.mk b/tests/automake.mk index 516949dd..af443504 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -146,7 +146,6 @@ dist_TESTS += tests/command/get-data-psql.sh endif nodist_TESTS = \ - tests/libpspp/str-test \ tests/libpspp/string-map-test \ tests/libpspp/stringi-map-test \ tests/libpspp/string-set-test \ @@ -171,6 +170,7 @@ check_PROGRAMS += \ tests/libpspp/range-set-test \ tests/libpspp/sparse-array-test \ tests/libpspp/sparse-xarray-test \ + tests/libpspp/str-test \ tests/output/render-test tests_data_datasheet_test_SOURCES = \ @@ -429,6 +429,7 @@ TESTSUITE_AT = \ tests/libpspp/range-map.at \ tests/libpspp/range-set.at \ tests/libpspp/sparse-array.at \ + tests/libpspp/str.at \ tests/math/moments.at \ tests/output/render.at \ tests/output/charts.at \ diff --git a/tests/libpspp/str-test.c b/tests/libpspp/str-test.c index 4e3867f4..c341d887 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 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 @@ -22,9 +22,6 @@ #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 @@ -47,7 +44,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 +60,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; + } } diff --git a/tests/libpspp/str.at b/tests/libpspp/str.at new file mode 100644 index 00000000..83ccc958 --- /dev/null +++ b/tests/libpspp/str.at @@ -0,0 +1,5 @@ +AT_BANNER([string library]) + +AT_SETUP([26-adic string formatting]) +AT_CHECK([str-test format-26adic]) +AT_CLEANUP