diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/printf.toc (renamed from tests/where.toc) | 9 | ||||
-rw-r--r-- | tests/printf_expected | 3 | ||||
-rwxr-xr-x | tests/test.sh | 4 | ||||
-rw-r--r-- | tests/where_expected | 1 |
4 files changed, 13 insertions, 4 deletions
diff --git a/tests/where.toc b/tests/printf.toc index 4223656..e030af4 100644 --- a/tests/where.toc +++ b/tests/printf.toc @@ -1,5 +1,7 @@ printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int; + +// NOTE: this doesn't work (e.g. "%%%") tprintf_valid ::= fn(fmt :: []char, nargs: int) bool { if fmt[fmt.len-1] != '\0' { return false; @@ -20,11 +22,16 @@ tprintf_valid ::= fn(fmt :: []char, nargs: int) bool { }; -tprintf ::= fn(fmt :: []char, args: ..) where tprintf_valid(fmt, args.len) { +tprintf ::= fn(fmt :: []char, args: ..) { + #if !tprintf_valid(fmt, args.len) { + #error "Invalid printf format"; + } f := fmt; printf(&f[0], args); }; main ::= fn() { tprintf("%d %d%%\n\0", 3, 4); + tprintf("%d %d %d%%\n\0", 3, 4, 5); + tprintf("Hello!\n\0"); }; diff --git a/tests/printf_expected b/tests/printf_expected new file mode 100644 index 0000000..a5e51ec --- /dev/null +++ b/tests/printf_expected @@ -0,0 +1,3 @@ +3 4% +3 4 5% +Hello! diff --git a/tests/test.sh b/tests/test.sh index 31ccb6b..d30de7c 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -8,7 +8,7 @@ foreign params nms varargs -where +printf misc' STARTPWD=$(pwd) @@ -22,7 +22,7 @@ compile_c() { if [ "$CC" = "gcc -O0 -g" ]; then EXTRA_FLAGS="-Wno-builtin-declaration-mismatch" elif [ "$CC" = "clang -O3 -s" ]; then - EXTRA_FLAGS="-Wno-builtin-requires-header" + EXTRA_FLAGS="-Wno-builtin-requires-header -Wno-format-security" elif [ "$CC" = "tcc" ]; then EXTRA_FLAGS="-w" fi diff --git a/tests/where_expected b/tests/where_expected deleted file mode 100644 index 622c000..0000000 --- a/tests/where_expected +++ /dev/null @@ -1 +0,0 @@ -3 4% |