]> git.draconx.ca Git - cdecl99.git/commitdiff
Add a simple test to check if cdecl99 rejects bogus input.
authorNick Bowler <nbowler@draconx.ca>
Fri, 23 Mar 2012 19:38:49 +0000 (15:38 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 23 Mar 2012 19:38:49 +0000 (15:38 -0400)
Makefile.am
tests/cdecl99-c-invalid.sh [new file with mode: 0755]

index 296a2224696fb540649d2997109047f405825315..4972bd27b1bf716723ac3fa91a1a19ac27348a6c 100644 (file)
@@ -75,7 +75,8 @@ TEST_EXTENSIONS = .sh
 SH_LOG_COMPILER = $(SHELL)
 
 TESTS = tests/libcdecl-static-symbols.sh tests/randomdecl-sanity.sh \
-       tests/crossparse-c-random.sh
+       tests/crossparse-c-random.sh tests/cdecl99-c-invalid.sh
+
 EXTRA_DIST += $(TESTS)
 
 src/parse.lo: src/scan.h
diff --git a/tests/cdecl99-c-invalid.sh b/tests/cdecl99-c-invalid.sh
new file mode 100755 (executable)
index 0000000..e20af03
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# Copyright © 2012 Nick Bowler
+#
+# Check that cdecl99 rejects a variety of invalid declarations.
+#
+# 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.
+
+cdecl99=./cdecl99$EXEEXT
+scriptname=$0
+
+test_decl() {
+       if $cdecl99 -e "explain $*" >/dev/null 2>&1; then
+               printf '%s: %s not rejected\n' "$scriptname" "$*" 1>&2
+               return 1
+       fi
+
+       return 0
+}
+
+set -e
+test_decl 'inline int x'
+test_decl 'restrict int x'
+test_decl 'static auto int x'
+test_decl 'auto x'
+test_decl 'int _Complex x'
+test_decl 'typedef int'
+test_decl 'void f(...)'
+# XXX: While these silly void-parameter declarations are "obviously" invalid, I
+# can't actually find a statement in the specification which forbids them.
+test_decl 'void f(void, void)'
+test_decl 'void f(register void)'
+test_decl 'void f(const void)'
+test_decl 'void f(const)'
+test_decl 'void f(typedef int x)'
+test_decl 'void f(static int x)'
+test_decl 'int f(void)[1]'
+test_decl 'int a[0]'
+test_decl 'void a[1]'
+test_decl 'int a[1](void)'