Extended test case for special characters to compiler arguments

pull/7245/head
Jon Turney 6 years ago committed by Dan Kegel
parent 92ee8932cd
commit 2f070c54bd
  1. 10
      test cases/common/145 special characters/arg-char-test.c
  2. 12
      test cases/common/145 special characters/arg-string-test.c
  3. 17
      test cases/common/145 special characters/arg-unquoted-test.c
  4. 38
      test cases/common/145 special characters/meson.build

@ -0,0 +1,10 @@
#include <assert.h>
#include <stdio.h>
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]);
}

@ -0,0 +1,12 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
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]);
}

@ -0,0 +1,17 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#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
}

@ -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

Loading…
Cancel
Save