From 2f070c54bd415bbe2207fbd313c346d26f003215 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Sun, 14 Apr 2019 14:16:17 +0100 Subject: Extended test case for special characters to compiler arguments --- .../common/145 special characters/arg-char-test.c | 10 ++++++ .../145 special characters/arg-string-test.c | 12 +++++++ .../145 special characters/arg-unquoted-test.c | 17 ++++++++++ .../common/145 special characters/meson.build | 38 ++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 test cases/common/145 special characters/arg-char-test.c create mode 100644 test cases/common/145 special characters/arg-string-test.c create mode 100644 test cases/common/145 special characters/arg-unquoted-test.c (limited to 'test cases/common') diff --git a/test cases/common/145 special characters/arg-char-test.c b/test cases/common/145 special characters/arg-char-test.c new file mode 100644 index 0000000..04e02f8 --- /dev/null +++ b/test cases/common/145 special characters/arg-char-test.c @@ -0,0 +1,10 @@ +#include +#include + +int main(int argc, char **argv) { + char c = CHAR; + assert(argc == 2); + if (c != argv[1][0]) + fprintf(stderr, "Expected %x, got %x\n", (unsigned int) c, (unsigned int) argv[1][0]); + assert(c == argv[1][0]); +} diff --git a/test cases/common/145 special characters/arg-string-test.c b/test cases/common/145 special characters/arg-string-test.c new file mode 100644 index 0000000..199fd79 --- /dev/null +++ b/test cases/common/145 special characters/arg-string-test.c @@ -0,0 +1,12 @@ +#include +#include +#include + +int main(int argc, char **argv) { + const char *s = CHAR; + assert(argc == 2); + assert(strlen(s) == 1); + if (s[0] != argv[1][0]) + fprintf(stderr, "Expected %x, got %x\n", (unsigned int) s[0], (unsigned int) argv[1][0]); + assert(s[0] == argv[1][0]); +} diff --git a/test cases/common/145 special characters/arg-unquoted-test.c b/test cases/common/145 special characters/arg-unquoted-test.c new file mode 100644 index 0000000..7f679ca --- /dev/null +++ b/test cases/common/145 special characters/arg-unquoted-test.c @@ -0,0 +1,17 @@ +#include +#include +#include + +#define Q(x) #x +#define QUOTE(x) Q(x) + +int main(int argc, char **argv) { + const char *s = QUOTE(CHAR); + assert(argc == 2); + assert(strlen(s) == 1); + if (s[0] != argv[1][0]) + fprintf(stderr, "Expected %x, got %x\n", (unsigned int) s[0], (unsigned int) argv[1][0]); + assert(s[0] == argv[1][0]); + // There is no way to convert a macro argument into a character constant. + // Otherwise we'd test that as well +} diff --git a/test cases/common/145 special characters/meson.build b/test cases/common/145 special characters/meson.build index ecba650..579601e 100644 --- a/test cases/common/145 special characters/meson.build +++ b/test cases/common/145 special characters/meson.build @@ -35,3 +35,41 @@ gen2 = custom_target('gen2', output : 'result2', install : true, install_dir : get_option('datadir')) + +# Test that we can pass these special characters in compiler arguments +# +# (this part of the test is crafted so we don't try to use these special +# characters in filenames or target names) +# +# TODO: similar tests needed for languages other than C +# TODO: add similar test for quote, doublequote, and hash, carefully +# Re hash, see +# https://docs.microsoft.com/en-us/cpp/build/reference/d-preprocessor-definitions + +special = [ + ['amp', '&'], + ['at', '@'], + ['backslash', '\\'], + ['dollar', '$'], + ['gt', '>'], + ['lt', '<'], + ['slash', '/'], +] + +cc = meson.get_compiler('c') + +foreach s : special + args = '-DCHAR="@0@"'.format(s[1]) + e = executable('arg-string-' + s[0], 'arg-string-test.c', c_args: args) + test('arg-string-' + s[0], e, args: s[1]) + + args = '-DCHAR=@0@'.format(s[1]) + e = executable('arg-unquoted-' + s[0], 'arg-unquoted-test.c', c_args: args) + test('arg-unquoted-' + s[0], e, args: s[1]) +endforeach + +foreach s : special + args = '-DCHAR=\'@0@\''.format(s[1]) + e = executable('arg-char-' + s[0], 'arg-char-test.c', c_args: args) + test('arg-char-' + s[0], e, args: s[1]) +endforeach -- cgit v1.1