llx: Convert tests to use Autotest.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 25 Sep 2010 21:27:10 +0000 (14:27 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 25 Sep 2010 23:02:27 +0000 (16:02 -0700)
tests/automake.mk
tests/libpspp/llx-test.c
tests/libpspp/llx.at [new file with mode: 0644]

index 127bbdb9cae576ef3953508b803d5d856d2d88b2..7146f1c7419979c1b82d1b63685eb3dbade5398c 100644 (file)
@@ -146,7 +146,6 @@ dist_TESTS += tests/command/get-data-psql.sh
 endif
 
 nodist_TESTS = \
-       tests/libpspp/llx-test \
        tests/libpspp/range-map-test \
        tests/libpspp/range-set-test \
        tests/libpspp/sparse-array-test \
@@ -170,6 +169,7 @@ check_PROGRAMS += \
        tests/libpspp/hmapx-test \
        tests/libpspp/i18n-test \
        tests/libpspp/ll-test \
+       tests/libpspp/llx-test \
        tests/libpspp/sparse-xarray-test \
        tests/output/render-test
 
@@ -425,6 +425,7 @@ TESTSUITE_AT = \
        tests/libpspp/hmapx.at \
        tests/libpspp/i18n.at \
        tests/libpspp/ll.at \
+       tests/libpspp/llx.at \
        tests/math/moments.at \
        tests/output/render.at \
        tests/output/charts.at \
index f8fe9b73618578f50f8dad56f18a3c261122b3f3..34f46e8bbf8042105ad808ab8ee4266e79d2f708 100644 (file)
@@ -42,9 +42,6 @@
 #define UNUSED
 #endif
 
-/* Currently running test. */
-static const char *test_name;
-
 /* Exit with a failure code.
    (Place a breakpoint on this function while debugging.) */
 static void
@@ -60,8 +57,7 @@ check_func (bool ok, int line)
 {
   if (!ok)
     {
-      printf ("Check failed in %s test at %s, line %d\n",
-              test_name, __FILE__, line);
+      fprintf (stderr, "%s:%d: check failed\n", __FILE__, line);
       check_die ();
     }
 }
@@ -2047,58 +2043,209 @@ test_allocation_failure (void)
 \f
 /* 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[] =
+  {
+    {
+      "push-pop",
+      "push/pop",
+      test_push_pop
+    },
+    {
+      "insert-remove",
+      "insert/remove",
+      test_insert_remove
+    },
+    {
+      "swap",
+      "swap",
+      test_swap
+    },
+    {
+      "swap-range",
+      "swap_range",
+      test_swap_range
+    },
+    {
+      "remove-range",
+      "remove_range",
+      test_remove_range
+    },
+    {
+      "remove-equal",
+      "remove_equal",
+      test_remove_equal
+    },
+    {
+      "remove-if",
+      "remove_if",
+      test_remove_if
+    },
+    {
+      "find-equal",
+      "find_equal",
+      test_find_equal
+    },
+    {
+      "find",
+      "find",
+      test_find
+    },
+    {
+      "find-if",
+      "find_if",
+      test_find_if
+    },
+    {
+      "find-adjacent-equal",
+      "find_adjacent_equal",
+      test_find_adjacent_equal
+    },
+    {
+      "count-range",
+      "count_range",
+      test_count_range
+    },
+    {
+      "count-equal",
+      "count_equal",
+      test_count_equal
+    },
+    {
+      "count-if",
+      "count_if",
+      test_count_if
+    },
+    {
+      "min-max",
+      "min/max",
+      test_min_max
+    },
+    {
+      "lexicographical-compare-3way",
+      "lexicographical_compare_3way",
+      test_lexicographical_compare_3way
+    },
+    {
+      "apply",
+      "apply",
+      test_apply
+    },
+    {
+      "destroy",
+      "destroy",
+      test_destroy
+    },
+    {
+      "reverse",
+      "reverse",
+      test_reverse
+    },
+    {
+      "permutations-no-dups",
+      "permutations (no dups)",
+      test_permutations_no_dups
+    },
+    {
+      "permutations-with-dups",
+      "permutations (with dups)",
+      test_permutations_with_dups
+    },
+    {
+      "merge-no-dups",
+      "merge (no dups)",
+      test_merge_no_dups
+    },
+    {
+      "merge-with-dups",
+      "merge (with dups)",
+      test_merge_with_dups
+    },
+    {
+      "sort-exhaustive",
+      "sort (exhaustive)",
+      test_sort_exhaustive
+    },
+    {
+      "sort-stable",
+      "sort (stability)",
+      test_sort_stable
+    },
+    {
+      "sort-subset",
+      "sort (subset)",
+      test_sort_subset
+    },
+    {
+      "sort-big",
+      "sort (big)",
+      test_sort_big
+    },
+    {
+      "unique",
+      "unique",
+      test_unique
+    },
+    {
+      "sort-unique",
+      "sort_unique",
+      test_sort_unique
+    },
+    {
+      "insert-ordered",
+      "insert_ordered",
+      test_insert_ordered
+    },
+    {
+      "partition",
+      "partition",
+      test_partition
+    },
+    {
+      "allocation-failure",
+      "allocation failure",
+      test_allocation_failure
+    },
+  };
+
+enum { N_TESTS = sizeof tests / sizeof *tests };
 
 int
-main (void)
-{
-  run_test (test_push_pop, "push/pop");
-  run_test (test_insert_remove, "insert/remove");
-  run_test (test_swap, "swap");
-  run_test (test_swap_range, "swap_range");
-  run_test (test_remove_range, "remove_range");
-  run_test (test_remove_equal, "remove_equal");
-  run_test (test_remove_if, "remove_if");
-  run_test (test_find_equal, "find_equal");
-  run_test (test_find, "find");
-  run_test (test_find_if, "find_if");
-  run_test (test_find_adjacent_equal, "find_adjacent_equal");
-  run_test (test_count_range, "count_range");
-  run_test (test_count_equal, "count_equal");
-  run_test (test_count_if, "count_if");
-  run_test (test_min_max, "min/max");
-  run_test (test_lexicographical_compare_3way, "lexicographical_compare_3way");
-  run_test (test_apply, "apply");
-  run_test (test_destroy, "destroy");
-  run_test (test_reverse, "reverse");
-  run_test (test_permutations_no_dups, "permutations (no dups)");
-  run_test (test_permutations_with_dups, "permutations (with dups)");
-  run_test (test_merge_no_dups, "merge (no dups)");
-  run_test (test_merge_with_dups, "merge (with dups)");
-  run_test (test_sort_exhaustive, "sort (exhaustive)");
-  run_test (test_sort_stable, "sort (stability)");
-  run_test (test_sort_subset, "sort (subset)");
-  run_test (test_sort_big, "sort (big)");
-  run_test (test_unique, "unique");
-  run_test (test_sort_unique, "sort_unique");
-  run_test (test_insert_ordered, "insert_ordered");
-  run_test (test_partition, "partition");
-  run_test (test_allocation_failure, "allocation failure");
-  putchar ('\n');
-
-  return 0;
-}
-
-/*
-  Local Variables:
-  compile-command: "gcc -Wall -Wstrict-prototypes -Wmissing-prototypes ll.c llx.c llx-test.c -o llx-test -g"
-  End:
- */
+main (int argc, char *argv[])
+{
+  int i;
+
+  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 doubly linked list of pointers (llx) 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/llx.at b/tests/libpspp/llx.at
new file mode 100644 (file)
index 0000000..973f925
--- /dev/null
@@ -0,0 +1,39 @@
+AT_BANNER([doubly linked list of pointers (llx) library])
+
+m4_define([CHECK_LLX],
+  [AT_SETUP([llx -- $1])
+   AT_CHECK([llx-test $1])
+   AT_CLEANUP])
+
+CHECK_LLX([push-pop])
+CHECK_LLX([insert-remove])
+CHECK_LLX([swap])
+CHECK_LLX([swap-range])
+CHECK_LLX([remove-range])
+CHECK_LLX([remove-equal])
+CHECK_LLX([remove-if])
+CHECK_LLX([find-equal])
+CHECK_LLX([find])
+CHECK_LLX([find-if])
+CHECK_LLX([find-adjacent-equal])
+CHECK_LLX([count-range])
+CHECK_LLX([count-equal])
+CHECK_LLX([count-if])
+CHECK_LLX([min-max])
+CHECK_LLX([lexicographical-compare-3way])
+CHECK_LLX([apply])
+CHECK_LLX([destroy])
+CHECK_LLX([reverse])
+CHECK_LLX([permutations-no-dups])
+CHECK_LLX([permutations-with-dups])
+CHECK_LLX([merge-no-dups])
+CHECK_LLX([merge-with-dups])
+CHECK_LLX([sort-exhaustive])
+CHECK_LLX([sort-stable])
+CHECK_LLX([sort-subset])
+CHECK_LLX([sort-big])
+CHECK_LLX([unique])
+CHECK_LLX([sort-unique])
+CHECK_LLX([insert-ordered])
+CHECK_LLX([partition])
+CHECK_LLX([allocation-failure])