diff options
Diffstat (limited to 'test cases/d')
63 files changed, 964 insertions, 0 deletions
diff --git a/test cases/d/1 simple/app.d b/test cases/d/1 simple/app.d new file mode 100644 index 0000000..0be1d2c --- /dev/null +++ b/test cases/d/1 simple/app.d @@ -0,0 +1,8 @@ + +import std.stdio; +import utils; + +void main () +{ + printGreeting ("a Meson D test"); +} diff --git a/test cases/d/1 simple/meson.build b/test cases/d/1 simple/meson.build new file mode 100644 index 0000000..a10b67b --- /dev/null +++ b/test cases/d/1 simple/meson.build @@ -0,0 +1,4 @@ +project('D Simple Test', 'd') + +e = executable('dsimpleapp', ['app.d', 'utils.d'], install : true) +test('apptest', e) diff --git a/test cases/d/1 simple/test.json b/test cases/d/1 simple/test.json new file mode 100644 index 0000000..62f907a --- /dev/null +++ b/test cases/d/1 simple/test.json @@ -0,0 +1,6 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/dsimpleapp"}, + {"type": "pdb", "file": "usr/bin/dsimpleapp", "language": "d"} + ] +} diff --git a/test cases/d/1 simple/utils.d b/test cases/d/1 simple/utils.d new file mode 100644 index 0000000..8645548 --- /dev/null +++ b/test cases/d/1 simple/utils.d @@ -0,0 +1,8 @@ + +import std.stdio; +import std.string : format; + +void printGreeting (string name) +{ + writeln ("Hello, I am %s.".format (name)); +} diff --git a/test cases/d/10 d cpp/cppmain.cpp b/test cases/d/10 d cpp/cppmain.cpp new file mode 100644 index 0000000..bcd8c7a --- /dev/null +++ b/test cases/d/10 d cpp/cppmain.cpp @@ -0,0 +1,18 @@ +extern "C" int rt_init(); +extern "C" int rt_term(); +extern void print_hello(int i); + +int main(int, char**) { + // initialize D runtime + if (!rt_init()) + return 1; + + print_hello(1); + + // terminate D runtime, each initialize call + // must be paired with a terminate call. + if (!rt_term()) + return 1; + + return 0; +} diff --git a/test cases/d/10 d cpp/dmain.d b/test cases/d/10 d cpp/dmain.d new file mode 100644 index 0000000..bece25f --- /dev/null +++ b/test cases/d/10 d cpp/dmain.d @@ -0,0 +1,5 @@ +extern (C++) void print_hello(int i); + +void main() { + print_hello(1); +} diff --git a/test cases/d/10 d cpp/libfile.cpp b/test cases/d/10 d cpp/libfile.cpp new file mode 100644 index 0000000..2ea67fc --- /dev/null +++ b/test cases/d/10 d cpp/libfile.cpp @@ -0,0 +1,5 @@ +#include<iostream> + +void print_hello(int i) { + std::cout << "Hello. Here is a number printed with C++: " << i << ".\n"; +} diff --git a/test cases/d/10 d cpp/libfile.d b/test cases/d/10 d cpp/libfile.d new file mode 100644 index 0000000..88cb53e --- /dev/null +++ b/test cases/d/10 d cpp/libfile.d @@ -0,0 +1,5 @@ +import std.stdio; + +extern (C++) void print_hello(int i) { + writefln("Hello. Here is a number printed with D: %d", i); +} diff --git a/test cases/d/10 d cpp/meson.build b/test cases/d/10 d cpp/meson.build new file mode 100644 index 0000000..eecb151 --- /dev/null +++ b/test cases/d/10 d cpp/meson.build @@ -0,0 +1,13 @@ +project('d and c++', 'd', 'cpp') + +cpp = meson.get_compiler('cpp') + +if cpp.get_id() == 'clang' + error('MESON_SKIP_TEST combining Clang C++ with GDC produces broken executables.') +endif + +e1 = executable('dcpp', 'dmain.d', 'libfile.cpp') +test('dcpp', e1) + +e2 = executable('cppd', 'cppmain.cpp', 'libfile.d') +test('cppd', e2) diff --git a/test cases/d/11 dub/.gitignore b/test cases/d/11 dub/.gitignore new file mode 100644 index 0000000..da3feeb --- /dev/null +++ b/test cases/d/11 dub/.gitignore @@ -0,0 +1 @@ +dub.json diff --git a/test cases/d/11 dub/meson.build b/test cases/d/11 dub/meson.build new file mode 100644 index 0000000..d852ca0 --- /dev/null +++ b/test cases/d/11 dub/meson.build @@ -0,0 +1,23 @@ +project('dub-example', 'd') + +dub_exe = find_program('dub', required : false) +if not dub_exe.found() + error('MESON_SKIP_TEST: Dub not found') +endif + +urld_dep = dependency('urld', method: 'dub') + +test_exe = executable('test-urld', 'test.d', dependencies: urld_dep) +test('test urld', test_exe) + +# If you want meson to generate/update a dub.json file +dlang = import('dlang') +dlang.generate_dub_file(meson.project_name().to_lower(), meson.source_root(), + authors: 'Meson Team', + description: 'Test executable', + copyright: 'Copyright © 2018, Meson Team', + license: 'MIT', + sourceFiles: 'test.d', + targetType: 'executable', + dependencies: urld_dep +)
\ No newline at end of file diff --git a/test cases/d/11 dub/test.d b/test cases/d/11 dub/test.d new file mode 100644 index 0000000..7cf7a1d --- /dev/null +++ b/test cases/d/11 dub/test.d @@ -0,0 +1,14 @@ +import std.stdio; +import url; + +void main() { + URL url; + with (url) { + scheme = "soap.beep"; + host = "beep.example.net"; + port = 1772; + path = "/serverinfo/info"; + queryParams.add("token", "my-api-token"); + } + writeln(url); +}
\ No newline at end of file diff --git a/test cases/d/12 root include directory/meson.build b/test cases/d/12 root include directory/meson.build new file mode 100644 index 0000000..9501615 --- /dev/null +++ b/test cases/d/12 root include directory/meson.build @@ -0,0 +1,7 @@ +project('some', 'd') + +project_dep = declare_dependency( + include_directories: ['.'], +) +subdir('some') + diff --git a/test cases/d/12 root include directory/some/dlang/code.d b/test cases/d/12 root include directory/some/dlang/code.d new file mode 100644 index 0000000..0dd82a4 --- /dev/null +++ b/test cases/d/12 root include directory/some/dlang/code.d @@ -0,0 +1,7 @@ +void foo() {} + +version (Windows) +{ + import core.sys.windows.dll; + mixin SimpleDllMain; +} diff --git a/test cases/d/12 root include directory/some/dlang/meson.build b/test cases/d/12 root include directory/some/dlang/meson.build new file mode 100644 index 0000000..3f958b1 --- /dev/null +++ b/test cases/d/12 root include directory/some/dlang/meson.build @@ -0,0 +1,8 @@ +code_lib = library('code', + ['code.d'], + dependencies: [project_dep]) + +code_dep = declare_dependency( + link_with: code_lib, + dependencies: project_dep +)
\ No newline at end of file diff --git a/test cases/d/12 root include directory/some/meson.build b/test cases/d/12 root include directory/some/meson.build new file mode 100644 index 0000000..a549c09 --- /dev/null +++ b/test cases/d/12 root include directory/some/meson.build @@ -0,0 +1 @@ +subdir('dlang')
\ No newline at end of file diff --git a/test cases/d/13 declare dep/meson.build b/test cases/d/13 declare dep/meson.build new file mode 100644 index 0000000..eef9816 --- /dev/null +++ b/test cases/d/13 declare dep/meson.build @@ -0,0 +1,13 @@ +project('meson-d-sample', 'd', + version: '0.1.0', +) + +my_dep = declare_dependency( + d_module_versions: ['TestVersion', 1], + d_import_dirs: include_directories('views'), +) + +test_exe = executable('test-dep', 'test.d', + dependencies: my_dep, +) +test('test d features in declare_dependency', test_exe) diff --git a/test cases/d/13 declare dep/test.d b/test cases/d/13 declare dep/test.d new file mode 100644 index 0000000..3a89921 --- /dev/null +++ b/test cases/d/13 declare dep/test.d @@ -0,0 +1,15 @@ +module test; + + +int main() +{ + version(TestVersion) + { + enum testPhrase = import("test.txt"); + return testPhrase == "TEST PHRASE" ? 0 : 1; + } + else + { + return 1; + } +} diff --git a/test cases/d/13 declare dep/views/test.txt b/test cases/d/13 declare dep/views/test.txt new file mode 100644 index 0000000..19046d0 --- /dev/null +++ b/test cases/d/13 declare dep/views/test.txt @@ -0,0 +1 @@ +TEST PHRASE
\ No newline at end of file diff --git a/test cases/d/14 dub with deps/meson.build b/test cases/d/14 dub with deps/meson.build new file mode 100644 index 0000000..08f3080 --- /dev/null +++ b/test cases/d/14 dub with deps/meson.build @@ -0,0 +1,34 @@ +project('dub-with-deps-example', ['d']) + +dub_exe = find_program('dub', required : false) +if not dub_exe.found() + error('MESON_SKIP_TEST: Dub not found') +endif + +if meson.get_compiler('d').get_id() == 'gcc' + error('MESON_SKIP_TEST: can\'t build dependencies with GDC') +elif meson.get_compiler('d').get_id() == 'llvm' + dc = 'ldc2' +elif meson.get_compiler('d').get_id() == 'dmd' + dc = 'dmd' +endif + +arch = host_machine.cpu_family() + +if host_machine.system() == 'windows' + # check if toolchain is 32bits + sz = meson.get_compiler('d').sizeof('void*') + if arch == 'x86' or sz == 4 + arch = 'x86_mscoff' + endif +endif + +run_command('dub', 'run', 'dub-build-deep', '--yes', '--', 'xlsx', '--compiler', dc, '--arch', arch, + check: true, +) + +xlsx_dep = dependency('xlsx', method: 'dub') + +test_exe = executable('test-test6', 'test.d', dependencies: xlsx_dep) + +test('test dub with deps', test_exe) diff --git a/test cases/d/14 dub with deps/test.d b/test cases/d/14 dub with deps/test.d new file mode 100644 index 0000000..61b5bda --- /dev/null +++ b/test cases/d/14 dub with deps/test.d @@ -0,0 +1,59 @@ +module test; + +// testing import dirs +import xlsx; + +// dependency of xlsx +import dxml.dom; + +const xml = "<!-- comment -->\n" ~ + "<root>\n" ~ + " <foo>some text<whatever/></foo>\n" ~ + " <bar/>\n" ~ + " <baz></baz>\n" ~ + "</root>"; + +int main() +{ + // testing versions + version (Have_dxml) + { + import std.range.primitives : empty; + + auto dom = parseDOM(xml); + assert(dom.type == EntityType.elementStart); + assert(dom.name.empty); + assert(dom.children.length == 2); + + assert(dom.children[0].type == EntityType.comment); + assert(dom.children[0].text == " comment "); + + auto root = dom.children[1]; + assert(root.type == EntityType.elementStart); + assert(root.name == "root"); + assert(root.children.length == 3); + + auto foo = root.children[0]; + assert(foo.type == EntityType.elementStart); + assert(foo.name == "foo"); + assert(foo.children.length == 2); + + assert(foo.children[0].type == EntityType.text); + assert(foo.children[0].text == "some text"); + + assert(foo.children[1].type == EntityType.elementEmpty); + assert(foo.children[1].name == "whatever"); + + assert(root.children[1].type == EntityType.elementEmpty); + assert(root.children[1].name == "bar"); + + assert(root.children[2].type == EntityType.elementStart); + assert(root.children[2].name == "baz"); + assert(root.children[2].children.length == 0); + return 0; + } + else + { + return 1; + } +} diff --git a/test cases/d/15 compiler run checks/meson.build b/test cases/d/15 compiler run checks/meson.build new file mode 100644 index 0000000..a80e528 --- /dev/null +++ b/test cases/d/15 compiler run checks/meson.build @@ -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 + diff --git a/test cases/d/15 compiler run checks/test_sizeof.d b/test cases/d/15 compiler run checks/test_sizeof.d new file mode 100644 index 0000000..c7099d0 --- /dev/null +++ b/test cases/d/15 compiler run checks/test_sizeof.d @@ -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; +} diff --git a/test cases/d/16 code generation/exe.d b/test cases/d/16 code generation/exe.d new file mode 100644 index 0000000..0e24d6d --- /dev/null +++ b/test cases/d/16 code generation/exe.d @@ -0,0 +1,9 @@ +module exe; + +import generated; +import std.stdio; + +int main() +{ + return generatedString() == "Some text to be returned by generated code" ? 0 : 1; +} diff --git a/test cases/d/16 code generation/generator.d b/test cases/d/16 code generation/generator.d new file mode 100644 index 0000000..f944dd3 --- /dev/null +++ b/test cases/d/16 code generation/generator.d @@ -0,0 +1,13 @@ +module generator; + +import std.file; +import std.stdio; +import std.string; + +void main(string[] args) +{ + const text = cast(string)read(args[1]); + + writeln("module generated;"); + writefln!`string generatedString() { return "%s"; }`(text.strip()); +} diff --git a/test cases/d/16 code generation/input.txt b/test cases/d/16 code generation/input.txt new file mode 100644 index 0000000..aebcda8 --- /dev/null +++ b/test cases/d/16 code generation/input.txt @@ -0,0 +1 @@ +Some text to be returned by generated code diff --git a/test cases/d/16 code generation/meson.build b/test cases/d/16 code generation/meson.build new file mode 100644 index 0000000..2418aca --- /dev/null +++ b/test cases/d/16 code generation/meson.build @@ -0,0 +1,18 @@ +project('meson-dep-test', 'd') + +generator = executable('generator', 'generator.d') + +generated = custom_target('generated', + capture: true, + output: 'generated.d', + input: 'input.txt', + command: [ + generator, '@INPUT@' + ] +) + +exe = executable('exe', generated, 'exe.d', + include_directories: include_directories('.'), +) + +test('test exe', exe) diff --git a/test cases/d/2 static library/app.d b/test cases/d/2 static library/app.d new file mode 100644 index 0000000..5d84a69 --- /dev/null +++ b/test cases/d/2 static library/app.d @@ -0,0 +1,8 @@ + +import libstuff; + +void main () +{ + immutable ret = printLibraryString ("foo"); + assert (ret == 4); +} diff --git a/test cases/d/2 static library/libstuff.d b/test cases/d/2 static library/libstuff.d new file mode 100644 index 0000000..fd3b4d0 --- /dev/null +++ b/test cases/d/2 static library/libstuff.d @@ -0,0 +1,9 @@ + +import std.stdio; +import std.string : format; + +int printLibraryString (string str) +{ + writeln ("Static Library says: %s".format (str)); + return 4; +} diff --git a/test cases/d/2 static library/meson.build b/test cases/d/2 static library/meson.build new file mode 100644 index 0000000..88ed2cb --- /dev/null +++ b/test cases/d/2 static library/meson.build @@ -0,0 +1,5 @@ +project('D Static Library', 'd') + +lstatic = static_library('stuff', 'libstuff.d', install : true) +es = executable('app_s', 'app.d', link_with : lstatic, install : true) +test('linktest_static', es) diff --git a/test cases/d/2 static library/test.json b/test cases/d/2 static library/test.json new file mode 100644 index 0000000..6abb934 --- /dev/null +++ b/test cases/d/2 static library/test.json @@ -0,0 +1,7 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/app_s"}, + {"type": "pdb", "file": "usr/bin/app_s", "language": "d"}, + {"type": "file", "file": "usr/lib/libstuff.a"} + ] +} diff --git a/test cases/d/3 shared library/app.d b/test cases/d/3 shared library/app.d new file mode 100644 index 0000000..5d84a69 --- /dev/null +++ b/test cases/d/3 shared library/app.d @@ -0,0 +1,8 @@ + +import libstuff; + +void main () +{ + immutable ret = printLibraryString ("foo"); + assert (ret == 4); +} diff --git a/test cases/d/3 shared library/libstuff.d b/test cases/d/3 shared library/libstuff.d new file mode 100644 index 0000000..8205490 --- /dev/null +++ b/test cases/d/3 shared library/libstuff.d @@ -0,0 +1,14 @@ +import std.stdio; +import std.string : format; + +export int printLibraryString (string str) +{ + writeln ("Library says: %s".format (str)); + return 4; +} + +version (Windows) +{ + import core.sys.windows.dll; + mixin SimpleDllMain; +} diff --git a/test cases/d/3 shared library/libstuff.di b/test cases/d/3 shared library/libstuff.di new file mode 100644 index 0000000..b6454b1 --- /dev/null +++ b/test cases/d/3 shared library/libstuff.di @@ -0,0 +1,3 @@ +module libstuff; + +int printLibraryString (string str); diff --git a/test cases/d/3 shared library/lld-test.py b/test cases/d/3 shared library/lld-test.py new file mode 100644 index 0000000..3f32f59 --- /dev/null +++ b/test cases/d/3 shared library/lld-test.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('ldd') + parser.add_argument('bin') + args = parser.parse_args() + + p, o, _ = subprocess.run([args.ldd, args.bin], stdout=subprocess.PIPE) + assert p == 0 + o = o.decode() + assert 'libstuff.so =>' in o, 'libstuff so not in linker path.' + assert 'libstuff.so => not found' not in o, 'libstuff.so not found correctly' + + +if __name__ == '__main__': + main() diff --git a/test cases/d/3 shared library/meson.build b/test cases/d/3 shared library/meson.build new file mode 100644 index 0000000..fa41779 --- /dev/null +++ b/test cases/d/3 shared library/meson.build @@ -0,0 +1,26 @@ +project('D Shared Library', 'd') + +dc = meson.get_compiler('d') +if dc.get_id() == 'gcc' + if dc.version().version_compare('< 8') + error('MESON_SKIP_TEST: GDC < 8.0 can not build shared libraries') + endif +endif + +subdir('sub') +ed = executable('app_d', 'app.d', link_with : ldyn, install : true) +test('linktest_dyn', ed) + +# test D attributes for pkg-config +pkgc = import('pkgconfig') +pkgc.generate(name: 'test', + libraries: ldyn, + subdirs: 'd/stuff', + description: 'A test of D attributes to pkgconfig.generate.', + d_module_versions: ['Use_Static'] +) + +ldd = find_program('ldd', required : false) +if ldd.found() + test('ldd-test.py', ed) +endif diff --git a/test cases/d/3 shared library/sub/libstuff.d b/test cases/d/3 shared library/sub/libstuff.d new file mode 100644 index 0000000..8205490 --- /dev/null +++ b/test cases/d/3 shared library/sub/libstuff.d @@ -0,0 +1,14 @@ +import std.stdio; +import std.string : format; + +export int printLibraryString (string str) +{ + writeln ("Library says: %s".format (str)); + return 4; +} + +version (Windows) +{ + import core.sys.windows.dll; + mixin SimpleDllMain; +} diff --git a/test cases/d/3 shared library/sub/meson.build b/test cases/d/3 shared library/sub/meson.build new file mode 100644 index 0000000..1599a33 --- /dev/null +++ b/test cases/d/3 shared library/sub/meson.build @@ -0,0 +1 @@ +ldyn = shared_library('stuff', 'libstuff.d', install : true) diff --git a/test cases/d/3 shared library/test.json b/test cases/d/3 shared library/test.json new file mode 100644 index 0000000..50eb9cb --- /dev/null +++ b/test cases/d/3 shared library/test.json @@ -0,0 +1,11 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/app_d"}, + {"type": "pdb", "file": "usr/bin/app_d", "language": "d"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/stuff"}, + {"type": "pdb", "file": "usr/bin/stuff", "language": "d"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/stuff"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff.lib"}, + {"type": "file", "file": "usr/lib/pkgconfig/test.pc"} + ] +} diff --git a/test cases/d/4 library versions/lib.d b/test cases/d/4 library versions/lib.d new file mode 100644 index 0000000..f1e177d --- /dev/null +++ b/test cases/d/4 library versions/lib.d @@ -0,0 +1,16 @@ + +import std.stdio; +import std.string : format; + +@safe +export int printLibraryString (string str) +{ + writeln ("Library says: %s".format (str)); + return 4; +} + +version (Windows) +{ + import core.sys.windows.dll; + mixin SimpleDllMain; +} diff --git a/test cases/d/4 library versions/meson.build b/test cases/d/4 library versions/meson.build new file mode 100644 index 0000000..c745b92 --- /dev/null +++ b/test cases/d/4 library versions/meson.build @@ -0,0 +1,25 @@ +project('D library versions', 'd') + +dc = meson.get_compiler('d') +if dc.get_id() == 'gcc' + if dc.version().version_compare('< 8') + error('MESON_SKIP_TEST: GDC < 8.0 can not build shared libraries') + endif +endif + +shared_library('some', 'lib.d', + version : '1.2.3', + soversion : '0', + install : true) + +shared_library('noversion', 'lib.d', + install : true) + +shared_library('onlyversion', 'lib.d', + version : '1.4.5', + install : true) + +shared_library('onlysoversion', 'lib.d', + # Also test that int soversion is acceptable + soversion : 5, + install : true) diff --git a/test cases/d/4 library versions/test.json b/test cases/d/4 library versions/test.json new file mode 100644 index 0000000..23c95dd --- /dev/null +++ b/test cases/d/4 library versions/test.json @@ -0,0 +1,25 @@ +{ + "installed": [ + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/some"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/some", "version": "0"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/some", "version": "1.2.3"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/noversion"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlyversion"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlyversion", "version": "1"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlyversion", "version": "1.4.5"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlysoversion"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/onlysoversion", "version": "5"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/noversion"}, + {"type": "pdb", "file": "usr/bin/noversion", "language": "d"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/onlysoversion", "version": "5"}, + {"type": "pdb", "file": "usr/bin/onlysoversion", "version": "5", "language": "d"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/onlyversion", "version": "1"}, + {"type": "pdb", "file": "usr/bin/onlyversion", "version": "1", "language": "d"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/some", "version": "0"}, + {"type": "pdb", "file": "usr/bin/some", "version": "0", "language": "d"}, + {"type": "implib", "file": "usr/lib/noversion"}, + {"type": "implib", "file": "usr/lib/onlysoversion"}, + {"type": "implib", "file": "usr/lib/onlyversion"}, + {"type": "implib", "file": "usr/lib/some"} + ] +} diff --git a/test cases/d/5 mixed/app.d b/test cases/d/5 mixed/app.d new file mode 100644 index 0000000..6ab5d97 --- /dev/null +++ b/test cases/d/5 mixed/app.d @@ -0,0 +1,8 @@ + +extern(C) int printLibraryString(const char *str); + +void main () +{ + immutable ret = printLibraryString ("C foo"); + assert (ret == 3); +} diff --git a/test cases/d/5 mixed/libstuff.c b/test cases/d/5 mixed/libstuff.c new file mode 100644 index 0000000..92d6600 --- /dev/null +++ b/test cases/d/5 mixed/libstuff.c @@ -0,0 +1,18 @@ +#if defined _WIN32 || defined __CYGWIN__ + #define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +#include <stdio.h> + +int DLL_PUBLIC printLibraryString(const char *str) +{ + printf("C library says: %s", str); + return 3; +} diff --git a/test cases/d/5 mixed/meson.build b/test cases/d/5 mixed/meson.build new file mode 100644 index 0000000..3dad66d --- /dev/null +++ b/test cases/d/5 mixed/meson.build @@ -0,0 +1,9 @@ +project('Mixing C and D', 'd', 'c') + +ldyn = shared_library('stuff', 'libstuff.c', install : true) +ed = executable('appdc_d', 'app.d', link_with : ldyn, install : true) +test('linktest_cdyn', ed) + +lstatic = static_library('stuff', 'libstuff.c', install : true) +es = executable('appdc_s', 'app.d', link_with : lstatic, install : true) +test('linktest_cstatic', es) diff --git a/test cases/d/5 mixed/test.json b/test cases/d/5 mixed/test.json new file mode 100644 index 0000000..c95d0ca --- /dev/null +++ b/test cases/d/5 mixed/test.json @@ -0,0 +1,13 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/appdc_d"}, + {"type": "pdb", "file": "usr/bin/appdc_d", "language": "d"}, + {"type": "exe", "file": "usr/bin/appdc_s"}, + {"type": "pdb", "file": "usr/bin/appdc_s", "language": "d"}, + {"type": "file", "file": "usr/lib/libstuff.a"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/stuff"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/stuff"}, + {"type": "pdb", "file": "usr/bin/stuff", "language": "c"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff.lib"} + ] +} diff --git a/test cases/d/6 unittest/app.d b/test cases/d/6 unittest/app.d new file mode 100644 index 0000000..71c6414 --- /dev/null +++ b/test cases/d/6 unittest/app.d @@ -0,0 +1,38 @@ + +import std.stdio; + +uint getFour () +{ + auto getTwo () + { + return 1 + 1; + } + + return getTwo () + getTwo (); +} + +void main () +{ + import core.stdc.stdlib : exit; + + writeln ("Four: ", getFour ()); + exit (4); +} + +unittest +{ + writeln ("TEST"); + import core.stdc.stdlib : exit; + import second_unit; + + assert (getFour () > 2); + assert (getFour () == 4); + + // this is a regression test for https://github.com/mesonbuild/meson/issues/3337 + secondModuleTestFunc (); + + // we explicitly terminate here to give the unittest program a different exit + // code than the main application has. + // (this prevents the regular main() from being executed) + exit (0); +} diff --git a/test cases/d/6 unittest/meson.build b/test cases/d/6 unittest/meson.build new file mode 100644 index 0000000..49a0700 --- /dev/null +++ b/test cases/d/6 unittest/meson.build @@ -0,0 +1,8 @@ +project('D Unittests', 'd') + +e = executable('dapp', ['app.d', 'second_unit.d'], install : true) +test('dapp_run', e, should_fail: true) + +e_test = executable('dapp_test', ['app.d', 'second_unit.d'], + d_unittest: true) +test('dapp_test', e_test) diff --git a/test cases/d/6 unittest/second_unit.d b/test cases/d/6 unittest/second_unit.d new file mode 100644 index 0000000..fdb62a9 --- /dev/null +++ b/test cases/d/6 unittest/second_unit.d @@ -0,0 +1,10 @@ + +void secondModuleTestFunc () +{ + import std.stdio : writeln; + + version (unittest) + writeln ("Hello!"); + else + assert (0); +} diff --git a/test cases/d/6 unittest/test.json b/test cases/d/6 unittest/test.json new file mode 100644 index 0000000..adc4d75 --- /dev/null +++ b/test cases/d/6 unittest/test.json @@ -0,0 +1,6 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/dapp"}, + {"type": "pdb", "file": "usr/bin/dapp", "language": "d"} + ] +} diff --git a/test cases/d/7 multilib/app.d b/test cases/d/7 multilib/app.d new file mode 100644 index 0000000..892596a --- /dev/null +++ b/test cases/d/7 multilib/app.d @@ -0,0 +1,9 @@ + +import say1; +import say2; + +void main () +{ + assert (sayHello1 ("Dave") == 4); + assert (sayHello2 ("HAL 9000") == 8); +} diff --git a/test cases/d/7 multilib/meson.build b/test cases/d/7 multilib/meson.build new file mode 100644 index 0000000..1879c08 --- /dev/null +++ b/test cases/d/7 multilib/meson.build @@ -0,0 +1,24 @@ +project('D Multiple Versioned Shared Libraries', 'd') + +dc = meson.get_compiler('d') +if dc.get_id() == 'gcc' + if dc.version().version_compare('< 8') + error('MESON_SKIP_TEST: GDC < 8.0 can not build shared libraries') + endif +endif + +ldyn1 = shared_library('say1', + 'say1.d', + install: true, + version : '1.2.3', + soversion : '0' +) +ldyn2 = shared_library('say2', + 'say2.d', + install: true, + version : '1.2.4', + soversion : '1' +) + +ed = executable('app_d', 'app.d', link_with: [ldyn1, ldyn2], install: true) +test('multilink_test', ed) diff --git a/test cases/d/7 multilib/say1.d b/test cases/d/7 multilib/say1.d new file mode 100644 index 0000000..605fd23 --- /dev/null +++ b/test cases/d/7 multilib/say1.d @@ -0,0 +1,15 @@ + +import std.stdio; +import std.string : format; + +export int sayHello1 (string str) +{ + writeln ("Hello %s from library 1.".format (str)); + return 4; +} + +version (Windows) +{ + import core.sys.windows.dll; + mixin SimpleDllMain; +} diff --git a/test cases/d/7 multilib/say1.di b/test cases/d/7 multilib/say1.di new file mode 100644 index 0000000..8a9ff02 --- /dev/null +++ b/test cases/d/7 multilib/say1.di @@ -0,0 +1 @@ +int sayHello1 (string str); diff --git a/test cases/d/7 multilib/say2.d b/test cases/d/7 multilib/say2.d new file mode 100644 index 0000000..7270ebd --- /dev/null +++ b/test cases/d/7 multilib/say2.d @@ -0,0 +1,15 @@ + +import std.stdio; +import std.string : format; + +export int sayHello2 (string str) +{ + writeln ("Hello %s from library 2.".format (str)); + return 8; +} + +version (Windows) +{ + import core.sys.windows.dll; + mixin SimpleDllMain; +} diff --git a/test cases/d/7 multilib/say2.di b/test cases/d/7 multilib/say2.di new file mode 100644 index 0000000..da712f0 --- /dev/null +++ b/test cases/d/7 multilib/say2.di @@ -0,0 +1 @@ +int sayHello2 (string str); diff --git a/test cases/d/7 multilib/test.json b/test cases/d/7 multilib/test.json new file mode 100644 index 0000000..5944ae0 --- /dev/null +++ b/test cases/d/7 multilib/test.json @@ -0,0 +1,18 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/app_d"}, + {"type": "pdb", "file": "usr/bin/app_d", "language": "d"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say1"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say1", "version": "0"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say1", "version": "1.2.3"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say2"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say2", "version": "1"}, + {"type": "shared_lib", "platform": "gcc", "file": "usr/lib/say2", "version": "1.2.4"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/say1", "version": "0"}, + {"type": "pdb", "file": "usr/bin/say1", "version": "0", "language": "d"}, + {"type": "shared_lib", "platform": "msvc", "file": "usr/bin/say2", "version": "1"}, + {"type": "pdb", "file": "usr/bin/say2", "version": "1", "language": "d"}, + {"type": "implib", "file": "usr/lib/say1"}, + {"type": "implib", "file": "usr/lib/say2"} + ] +} diff --git a/test cases/d/8 has multi arguments/meson.build b/test cases/d/8 has multi arguments/meson.build new file mode 100644 index 0000000..0897057 --- /dev/null +++ b/test cases/d/8 has multi arguments/meson.build @@ -0,0 +1,8 @@ +project('D has arguments test', 'd') + +compiler = meson.get_compiler('d') + +assert(compiler.compiles('int i;'), 'Basic code test does not compile: ' + compiler.get_id()) +assert(compiler.has_multi_arguments(['-I.', '-J.']), 'Multi argument test does not work: ' + compiler.get_id()) +assert(compiler.has_argument('-I.'), 'Basic argument test does not work: ' + compiler.get_id()) +assert(compiler.has_argument('-flag_a_d_compiler_definitely_does_not_have') == false, 'Basic argument test does not work: ' + compiler.get_id()) diff --git a/test cases/d/9 features/app.d b/test cases/d/9 features/app.d new file mode 100644 index 0000000..ae59be1 --- /dev/null +++ b/test cases/d/9 features/app.d @@ -0,0 +1,82 @@ + +import std.stdio; +import std.array : split; +import std.string : strip; + +import extra; + +auto getMenu () +{ + auto foods = import ("food.txt").strip.split ("\n"); + return foods; +} + +auto getPeople () +{ + return import ("people.txt").strip.split ("\n"); +} + +void main (string[] args) +{ + import std.array : join; + import core.stdc.stdlib : exit; + + immutable request = args[1]; + if (request == "menu") { + version (No_Menu) { + } else { + writeln ("On the menu: ", getMenu.join (", ")); + exit (0); + } + } + + version (With_People) { + if (request == "people") { + writeln ("People: ", getPeople.join (", ")); + + // only exit successfully if the second module also had its module version set. + // this checks for issue https://github.com/mesonbuild/meson/issues/3337 + if (secondModulePeopleVersionSet ()) + exit (0); + exit (1); + } + } + + version (With_VersionInteger) + version(3) exit(0); + + version (With_Debug) + debug exit(0); + + version (With_DebugInteger) + debug(3) exit(0); + + version (With_DebugIdentifier) + debug(DebugIdentifier) exit(0); + + version (With_DebugAll) { + int dbg = 0; + debug dbg++; + debug(2) dbg++; + debug(3) dbg++; + debug(4) dbg++; + debug(DebugIdentifier) dbg++; + + if (dbg == 5) + exit(0); + } + + // we fail here + exit (1); +} + +unittest +{ + writeln ("TEST"); + import core.stdc.stdlib : exit; + + writeln(getMenu); + assert (getMenu () == ["Spam", "Eggs", "Spam", "Baked Beans", "Spam", "Spam"]); + + exit (0); +} diff --git a/test cases/d/9 features/data/food.txt b/test cases/d/9 features/data/food.txt new file mode 100644 index 0000000..8275dd0 --- /dev/null +++ b/test cases/d/9 features/data/food.txt @@ -0,0 +1,6 @@ +Spam +Eggs +Spam +Baked Beans +Spam +Spam diff --git a/test cases/d/9 features/data/people.txt b/test cases/d/9 features/data/people.txt new file mode 100644 index 0000000..abbae06 --- /dev/null +++ b/test cases/d/9 features/data/people.txt @@ -0,0 +1,5 @@ +Rick +Morty +Summer +Beth +Jerry diff --git a/test cases/d/9 features/extra.d b/test cases/d/9 features/extra.d new file mode 100644 index 0000000..832b292 --- /dev/null +++ b/test cases/d/9 features/extra.d @@ -0,0 +1,9 @@ + +auto secondModulePeopleVersionSet () +{ + version (With_People) { + return true; + } else { + return false; + } +} diff --git a/test cases/d/9 features/meson.build b/test cases/d/9 features/meson.build new file mode 100644 index 0000000..06f0341 --- /dev/null +++ b/test cases/d/9 features/meson.build @@ -0,0 +1,106 @@ +project('D Features', 'd', default_options : ['debug=false']) + +# ONLY FOR BACKWARDS COMPATIBILITY. +# DO NOT DO THIS IN NEW CODE! +# USE include_directories() INSTEAD OF BUILDING +# STRINGS TO PATHS MANUALLY! +data_dir = join_paths(meson.current_source_dir(), 'data') + +test_src = ['app.d', 'extra.d'] + +e_plain_bcompat = executable('dapp_menu_bcompat', + test_src, + d_import_dirs: [data_dir] +) +test('dapp_menu_t_fail_bcompat', e_plain_bcompat, should_fail: true) +test('dapp_menu_t_bcompat', e_plain_bcompat, args: ['menu']) + +# directory for data +# This is the correct way to do this. +data_dir = include_directories('data') + +e_plain = executable('dapp_menu', + test_src, + d_import_dirs: [data_dir] +) +test('dapp_menu_t_fail', e_plain, should_fail: true) +test('dapp_menu_t', e_plain, args: ['menu']) + + +# test feature versions and string imports +e_versions = executable('dapp_versions', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['No_Menu', 'With_People'] +) +test('dapp_versions_t_fail', e_versions, args: ['menu'], should_fail: true) +test('dapp_versions_t', e_versions, args: ['people']) + +# test everything and unittests +e_test = executable('dapp_test', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['No_Menu', 'With_People'], + d_unittest: true +) +test('dapp_test', e_test) + +# test version level +e_version_int = executable('dapp_version_int', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['With_VersionInteger', 3], +) +test('dapp_version_int_t', e_version_int, args: ['debug']) + +# test version level failure +e_version_int_fail = executable('dapp_version_int_fail', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['With_VersionInteger', 2], +) +test('dapp_version_int_t_fail', e_version_int_fail, args: ['debug'], should_fail: true) + +# test debug conditions: disabled +e_no_debug = executable('dapp_no_debug', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['With_Debug'], +) +test('dapp_no_debug_t_fail', e_no_debug, args: ['debug'], should_fail: true) + +# test debug conditions: enabled +e_debug = executable('dapp_debug', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['With_Debug'], + d_debug: 1, +) +test('dapp_debug_t', e_debug, args: ['debug']) + +# test debug conditions: integer +e_debug_int = executable('dapp_debug_int', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['With_DebugInteger'], + d_debug: 3, +) +test('dapp_debug_int_t', e_debug_int, args: ['debug']) + +# test debug conditions: identifier +e_debug_ident = executable('dapp_debug_ident', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['With_DebugIdentifier'], + d_debug: 'DebugIdentifier', +) +test('dapp_debug_ident_t', e_debug_ident, args: ['debug']) + +# test with all debug conditions at once, and with redundant values +e_debug_all = executable('dapp_debug_all', + test_src, + d_import_dirs: [data_dir], + d_module_versions: ['With_DebugAll'], + d_debug: ['4', 'DebugIdentifier', 2, 'DebugIdentifierUnused'], +) +test('dapp_debug_all_t', e_debug_all, args: ['debug']) |