| 1 |
project('tryrun', 'c', 'cpp') |
| 2 |
|
| 3 |
# Complex to exercise all code paths. |
| 4 |
if meson.is_cross_build() |
| 5 |
if meson.can_run_host_binaries() |
| 6 |
compilers = [meson.get_compiler('c', native : false), meson.get_compiler('cpp', native : false)] |
| 7 |
else |
| 8 |
compilers = [meson.get_compiler('c', native : true), meson.get_compiler('cpp', native : true)] |
| 9 |
endif |
| 10 |
else |
| 11 |
compilers = [meson.get_compiler('c'), meson.get_compiler('cpp')] |
| 12 |
endif |
| 13 |
|
| 14 |
ok_code = '''#include<stdio.h> |
| 15 |
int main(void) { |
| 16 |
printf("%s\n", "stdout"); |
| 17 |
fprintf(stderr, "%s\n", "stderr"); |
| 18 |
return 0; |
| 19 |
} |
| 20 |
''' |
| 21 |
|
| 22 |
error_code = '''int main(void) { |
| 23 |
return 1; |
| 24 |
} |
| 25 |
''' |
| 26 |
|
| 27 |
no_compile_code = '''int main(void) { |
| 28 |
''' |
| 29 |
|
| 30 |
INPUTS = [ |
| 31 |
['String', ok_code, error_code, no_compile_code], |
| 32 |
['File', files('ok.c'), files('error.c'), files('no_compile.c')], |
| 33 |
] |
| 34 |
|
| 35 |
foreach cc : compilers |
| 36 |
foreach input : INPUTS |
| 37 |
type = input[0] |
| 38 |
ok = cc.run(input[1], name : type + ' should succeed') |
| 39 |
err = cc.run(input[2], name : type + ' should fail') |
| 40 |
noc = cc.run(input[3], name : type + ' does not compile') |
| 41 |
|
| 42 |
if noc.compiled() |
| 43 |
error(type + ' compilation fail test failed.') |
| 44 |
else |
| 45 |
message(type + ' fail detected properly.') |
| 46 |
endif |
| 47 |
|
| 48 |
if ok.compiled() |
| 49 |
message(type + ' compilation worked.') |
| 50 |
else |
| 51 |
error(type + ' compilation did not work.') |
| 52 |
endif |
| 53 |
|
| 54 |
if ok.returncode() == 0 |
| 55 |
message(type + ' return code ok.') |
| 56 |
else |
| 57 |
error(type + ' return code fail') |
| 58 |
endif |
| 59 |
|
| 60 |
if err.returncode() == 1 |
| 61 |
message(type + ' bad return code ok.') |
| 62 |
else |
| 63 |
error(type + ' bad return code fail.') |
| 64 |
endif |
| 65 |
|
| 66 |
if ok.stdout().strip() == 'stdout' |
| 67 |
message(type + ' stdout ok.') |
| 68 |
else |
| 69 |
message(type + ' bad stdout.') |
| 70 |
endif |
| 71 |
|
| 72 |
if ok.stderr().strip() == 'stderr' |
| 73 |
message(type + ' stderr ok.') |
| 74 |
else |
| 75 |
message(type + ' bad stderr.') |
| 76 |
endif |
| 77 |
endforeach |
| 78 |
endforeach |