From 4c3b000fbd0d860b42823fde9271a34eb60ee51d Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sat, 25 Apr 2020 14:53:14 +0200 Subject: [PATCH] Added a few more printf() error tests. --- .../java/dk/camelot64/kickc/test/TestPrograms.java | 10 ++++++++++ src/test/kc/printf-error-4.c | 12 ++++++++++++ src/test/kc/printf-error-5.c | 9 +++++++++ 3 files changed, 31 insertions(+) create mode 100644 src/test/kc/printf-error-4.c create mode 100644 src/test/kc/printf-error-5.c diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 56bce5427..a57fdb3e0 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -40,6 +40,16 @@ public class TestPrograms { public TestPrograms() { } + @Test + public void testPrintfError5() throws IOException, URISyntaxException { + assertError("printf-error-5.c", "Error! printf() format parameter must be a string!"); + } + + @Test + public void testPrintfError4() throws IOException, URISyntaxException { + assertError("printf-error-4.c", "Error! Only constant printf() format parameter supported!"); + } + @Test public void testPrintfError3() throws IOException, URISyntaxException { assertError("printf-error-3.c", "Error! If any single printf() placeholder specifies a parameter, all the rest of the placeholders must also specify a parameter!"); diff --git a/src/test/kc/printf-error-4.c b/src/test/kc/printf-error-4.c new file mode 100644 index 000000000..f8ab110e0 --- /dev/null +++ b/src/test/kc/printf-error-4.c @@ -0,0 +1,12 @@ +// Tests printf function call rewriting +// Non-constant format parameter + +#include + +void main() { + char* fmt = "%d"; + printf(fmt, 1); + fmt = "%hhx"; + printf(fmt, 1); +} + diff --git a/src/test/kc/printf-error-5.c b/src/test/kc/printf-error-5.c new file mode 100644 index 000000000..69f5b0ebb --- /dev/null +++ b/src/test/kc/printf-error-5.c @@ -0,0 +1,9 @@ +// Tests printf function call rewriting +// Non-string format parameter + +#include + +void main() { + printf(1, 1); +} +