# This is free software: you are free to do what the fuck you want to.
# There is NO WARRANTY, to the extent permitted by law.
-AUTOMAKE_OPTIONS = parallel-tests color-tests
ACLOCAL_AMFLAGS = -I m4 -I common/m4
# For Gnulib
test_randomdecl_LDADD = libcdecl.la libtest.la libgnu.la
$(test_randomdecl_OBJECTS): $(gnulib_headers)
-TESTS_ENVIRONMENT = SHELL='$(SHELL)' LIBTOOL='$(LIBTOOL)' EXEEXT='$(EXEEXT)'
-TEST_EXTENSIONS = .sh
-SH_LOG_COMPILER = $(SHELL)
-
-TESTS = tests/crossparse-c-random.sh
-
-dist_check_SCRIPTS = $(TESTS)
-
src/parse.lo: src/scan.h
src/scan.lo: src/parse.h
src/parse-decl.lo: src/scan.h src/parse.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <stdbool.h>
#include <getopt.h>
#include <cdecl.h>
#define PROGNAME "crossparse"
static const char *progname = PROGNAME;
-static const char sopts[] = "ECVH";
+static const char sopts[] = "f:ECVH";
static const struct option lopts[] = {
{ "cdecl", 0, NULL, 'C' },
{ "english", 0, NULL, 'E' },
+ { "file", 2, NULL, 'f' },
{ "version", 0, NULL, 'V' },
{ "help", 0, NULL, 'H' },
{ 0 }
free(buf1);
free(buf2);
free(buf3);
+
+ if (!ret) {
+ fprintf(stderr, "%s: failed cross-parse check of: %s\n",
+ progname, str);
+ }
+
return ret;
}
int main(int argc, char **argv)
{
int opt, mode = MODE_CDECL;
- int ret = EXIT_FAILURE;
+ int ret = EXIT_SUCCESS;
+
+ const char *filename = NULL;
+ FILE *infile = NULL;
if (argc > 0)
progname = argv[0];
case 'E':
mode = MODE_ENGLISH;
break;
+ case 'f':
+ infile = stdin;
+ filename = optarg;
+ break;
case 'V':
test_print_version(PROGNAME);
return EXIT_SUCCESS;
}
}
- if (!argv[optind]) {
- print_usage(stderr);
- return EXIT_FAILURE;
- }
+ if (infile) {
+ char *line = NULL;
+ size_t n;
+
+ if (filename) {
+ infile = fopen(filename, "r");
+ if (!infile) {
+ fprintf(stderr, "%s: %s: %s\n", progname,
+ filename, strerror(errno));
+ return EXIT_FAILURE;
+ }
+ }
- for (int i = optind; i < argc; i++) {
- if (!test_crossparse(argv[i], mode)) {
- fprintf(stderr, "%s: failed cross-parse check of: %s\n",
- progname, argv[i]);
- return EXIT_FAILURE;
+ while (getline(&line, &n, infile) >= 0) {
+ char *c = strchr(line, '\n');
+ if (c)
+ *c = '\0';
+ if (!test_crossparse(line, mode))
+ ret = EXIT_FAILURE;
}
+ } else if (argv[optind]) {
+ for (int i = optind; i < argc; i++) {
+ if (!test_crossparse(argv[i], mode))
+ ret = EXIT_FAILURE;
+ }
+ } else {
+ print_usage(stderr);
+ return EXIT_FAILURE;
}
- return EXIT_SUCCESS;
+ return ret;
}
+++ /dev/null
-#!/bin/sh
-#
-# Copyright © 2012 Nick Bowler
-#
-# Randomized tests that libcdecl can parse its own output.
-#
-# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
-# This is free software: you are free to do what the fuck you want to.
-# There is NO WARRANTY, to the extent permitted by law.
-
-: "${RANDOMSEED=$RANDOM}" "${TESTITER=500}"
-
-randomdecl=test/randomdecl$EXEEXT
-crossparse=test/crossparse$EXEEXT
-test -x $randomdecl || exit 77
-
-# Slow case: run tests one at a time to determine exactly which one failed.
-first_failed() {
- ff_count=0
-
- while test $# -gt 0
- do
- $crossparse "$1" 2>/dev/null || break
- ff_count=`expr $ff_count + 1`
- shift
- done
-
- echo "$ff_count"
-}
-
-proc() {
- result=pass
- count=0
-
- set x
- while read decl
- do
- set "$@" "$decl"
-
- # Accumulate tests in $@ and run them in batches to avoid
- # significant startup costs.
- if test $# -gt 25; then
- shift
- $crossparse "$@" || { result=fail
- tmp_count=`first_failed "$@"`
- count=`expr $count + $tmp_count`
- break
- }
- count=`expr $count + $#`
- set x
- fi
- done
-
- shift
- if test $# -gt 0 && test x"$result" = x"pass"; then
- tmp_count=$#
- $crossparse "$@" || { result=fail
- tmp_count=`first_failed "$@"`
- }
- count=`expr $count + $tmp_count`
- fi
-
- echo "result=$result"
- echo "count=$count"
-}
-
-printf '%s: randomized test using RANDOMSEED=%d\n' "$0" "$RANDOMSEED"
-
-eval_cmd=`exec 3>&1
- { $randomdecl -s "$RANDOMSEED" -n "$TESTITER" 3>&-
- echo gen_status=$? >&3
- } | proc >&3`
-eval "$eval_cmd"
-
-if test x"$gen_status" != x"0"; then
- printf '%s: %s failed with status=%d\n' \
- "$0" "$randomdecl" "$gen_status" 1>&2
- exit 1
-fi
-
-expected_count=`expr "$TESTITER" + 0`
-if test x"$count" != x"$expected_count"; then
- printf '%s: failed after %d successful tests (out of %d)\n' \
- "$0" "$count" "$expected_count" 1>&2
- exit 1
-fi
-
-test x"$result" = x"pass" && exit 0
-exit 1
m4_map([sanity_check], [sanity_tests])
AT_CLEANUP
+
+AT_SETUP([random cross-parse])
+
+TEST_NEED_PROGRAM([randomdecl])
+TEST_NEED_PROGRAM([crossparse])
+
+printf 'Using seed %d\n' "$random_seed" >&AS_MESSAGE_LOG_FD
+AT_CHECK([randomdecl -n "$random_iter" -s "$random_seed"],, [stdout-nolog])
+AT_CHECK([crossparse -f stdout])
+AT_CLEANUP
[Integer seed for randomized testing (default: auto)])],
[random_seed=$at_optarg], [random_seed=$RANDOM$$])
+AT_ARG_OPTION_ARG([random-iterations],
+ [AS_HELP_STRING([--random-iterations=N],
+ [Number of randomized testcases to perform (default: 500)])],
+ [random_iter=$at_optarg], [random_iter=])
+
m4_divert_push([PREPARE_TESTS])dnl
: ${LIBTOOL="$SHELL $builddir/libtool"}
random_seed=`printf '%s' "$random_seed" | tr -cd '@<:@:digit:@:>@'`
random_seed=${random_seed:-0}
+random_iter=`printf '%s' "$random_iter" | tr -cd '@<:@:digit:@:>@'`
+random_iter=`expr "$random_iter" '|' 500`
m4_divert_pop([PREPARE_TESTS])
m4_define([TEST_NEED_PROGRAM], [AT_KEYWORDS([$1])dnl