- run - sizeof - alignment - has_headerpull/10331/head
parent
c16fdaeeca
commit
f24ad87e05
3 changed files with 166 additions and 2 deletions
@ -0,0 +1,50 @@ |
||||
project('test-d-run-checks', 'd') |
||||
|
||||
dc = meson.get_compiler('d') |
||||
|
||||
run_sizeof = dc.run('int main() { return (void*).sizeof; }') |
||||
if run_sizeof.returncode() == 8 |
||||
run_versions = ['Is64bits'] |
||||
elif run_sizeof.returncode() == 4 |
||||
run_versions = ['Is32bits'] |
||||
endif |
||||
run_sizeof_exe = executable('run_sizeof', 'test_sizeof.d', |
||||
d_module_versions: run_versions, |
||||
) |
||||
test('test D compiler run', run_sizeof_exe) |
||||
|
||||
sizeof_sizeof = dc.sizeof('void*') |
||||
if sizeof_sizeof == 8 |
||||
run_versions = ['Is64bits'] |
||||
elif sizeof_sizeof == 4 |
||||
run_versions = ['Is32bits'] |
||||
endif |
||||
sizeof_sizeof_exe = executable('sizeof_sizeof', 'test_sizeof.d', |
||||
d_module_versions: run_versions, |
||||
) |
||||
test('test D compiler sizeof', sizeof_sizeof_exe) |
||||
|
||||
if not dc.has_header('std.stdio') |
||||
error('Could not find std.stdio import') |
||||
endif |
||||
|
||||
if dc.has_header('not_a_d_module') |
||||
error('has_header inconsistent result') |
||||
endif |
||||
|
||||
# same checks as C/C++ alignments (D has same alignment requirements as C) |
||||
|
||||
# These tests should return the same value on all |
||||
# platforms. If (and when) they don't, fix 'em up. |
||||
if dc.alignment('char') != 1 |
||||
error('Alignment of char misdetected.') |
||||
endif |
||||
|
||||
dbl_alignment = dc.alignment('double') |
||||
|
||||
if dbl_alignment == 8 or dbl_alignment == 4 |
||||
message('Alignment of double ok.') |
||||
else |
||||
error('Alignment of double misdetected.') |
||||
endif |
||||
|
@ -0,0 +1,17 @@ |
||||
module test_sizeof; |
||||
|
||||
alias voidp = void*; |
||||
|
||||
int main() |
||||
{ |
||||
version(Is64bits) { |
||||
enum expectedSz = 8; |
||||
} |
||||
else version(Is32bits) { |
||||
enum expectedSz = 4; |
||||
} |
||||
else { |
||||
assert(false, "No version set!"); |
||||
} |
||||
return expectedSz == voidp.sizeof ? 0 : 1; |
||||
} |
Loading…
Reference in new issue