]> git.draconx.ca Git - cdecl99.git/blobdiff - tests/cdecl99-c-invalid.sh
Add a simple test to check if cdecl99 rejects bogus input.
[cdecl99.git] / tests / cdecl99-c-invalid.sh
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)'