diff options
Diffstat (limited to 'meson/test cases/d')
47 files changed, 711 insertions, 0 deletions
diff --git a/meson/test cases/d/1 simple/app.d b/meson/test cases/d/1 simple/app.d new file mode 100644 index 000000000..0be1d2cc7 --- /dev/null +++ b/meson/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/meson/test cases/d/1 simple/meson.build b/meson/test cases/d/1 simple/meson.build new file mode 100644 index 000000000..a10b67b10 --- /dev/null +++ b/meson/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/meson/test cases/d/1 simple/test.json b/meson/test cases/d/1 simple/test.json new file mode 100644 index 000000000..62f907a4c --- /dev/null +++ b/meson/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/meson/test cases/d/1 simple/utils.d b/meson/test cases/d/1 simple/utils.d new file mode 100644 index 000000000..8645548c5 --- /dev/null +++ b/meson/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/meson/test cases/d/10 d cpp/cppmain.cpp b/meson/test cases/d/10 d cpp/cppmain.cpp new file mode 100644 index 000000000..ff90e3f41 --- /dev/null +++ b/meson/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/meson/test cases/d/10 d cpp/dmain.d b/meson/test cases/d/10 d cpp/dmain.d new file mode 100644 index 000000000..bece25f6c --- /dev/null +++ b/meson/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/meson/test cases/d/10 d cpp/libfile.cpp b/meson/test cases/d/10 d cpp/libfile.cpp new file mode 100644 index 000000000..2ea67fc92 --- /dev/null +++ b/meson/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/meson/test cases/d/10 d cpp/libfile.d b/meson/test cases/d/10 d cpp/libfile.d new file mode 100644 index 000000000..88cb53e9b --- /dev/null +++ b/meson/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/meson/test cases/d/10 d cpp/meson.build b/meson/test cases/d/10 d cpp/meson.build new file mode 100644 index 000000000..eecb151f4 --- /dev/null +++ b/meson/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/meson/test cases/d/11 dub/meson.build b/meson/test cases/d/11 dub/meson.build new file mode 100644 index 000000000..d852ca0c2 --- /dev/null +++ b/meson/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/meson/test cases/d/11 dub/test.d b/meson/test cases/d/11 dub/test.d new file mode 100644 index 000000000..7cf7a1d58 --- /dev/null +++ b/meson/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/meson/test cases/d/2 static library/app.d b/meson/test cases/d/2 static library/app.d new file mode 100644 index 000000000..5d84a6942 --- /dev/null +++ b/meson/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/meson/test cases/d/2 static library/libstuff.d b/meson/test cases/d/2 static library/libstuff.d new file mode 100644 index 000000000..fd3b4d0b4 --- /dev/null +++ b/meson/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/meson/test cases/d/2 static library/meson.build b/meson/test cases/d/2 static library/meson.build new file mode 100644 index 000000000..88ed2cb8f --- /dev/null +++ b/meson/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/meson/test cases/d/2 static library/test.json b/meson/test cases/d/2 static library/test.json new file mode 100644 index 000000000..6abb93409 --- /dev/null +++ b/meson/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/meson/test cases/d/3 shared library/app.d b/meson/test cases/d/3 shared library/app.d new file mode 100644 index 000000000..5d84a6942 --- /dev/null +++ b/meson/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/meson/test cases/d/3 shared library/libstuff.d b/meson/test cases/d/3 shared library/libstuff.d new file mode 100644 index 000000000..8205490f7 --- /dev/null +++ b/meson/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/meson/test cases/d/3 shared library/libstuff.di b/meson/test cases/d/3 shared library/libstuff.di new file mode 100644 index 000000000..b6454b180 --- /dev/null +++ b/meson/test cases/d/3 shared library/libstuff.di @@ -0,0 +1,3 @@ +module libstuff; + +int printLibraryString (string str); diff --git a/meson/test cases/d/3 shared library/lld-test.py b/meson/test cases/d/3 shared library/lld-test.py new file mode 100644 index 000000000..3f32f59fb --- /dev/null +++ b/meson/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/meson/test cases/d/3 shared library/meson.build b/meson/test cases/d/3 shared library/meson.build new file mode 100644 index 000000000..fa417794c --- /dev/null +++ b/meson/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/meson/test cases/d/3 shared library/sub/libstuff.d b/meson/test cases/d/3 shared library/sub/libstuff.d new file mode 100644 index 000000000..8205490f7 --- /dev/null +++ b/meson/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/meson/test cases/d/3 shared library/sub/meson.build b/meson/test cases/d/3 shared library/sub/meson.build new file mode 100644 index 000000000..fb4b99661 --- /dev/null +++ b/meson/test cases/d/3 shared library/sub/meson.build @@ -0,0 +1,2 @@ +ldyn = shared_library('stuff', 'libstuff.d', install : true) + diff --git a/meson/test cases/d/3 shared library/test.json b/meson/test cases/d/3 shared library/test.json new file mode 100644 index 000000000..50eb9cbdd --- /dev/null +++ b/meson/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/meson/test cases/d/4 library versions/lib.d b/meson/test cases/d/4 library versions/lib.d new file mode 100644 index 000000000..f1e177d99 --- /dev/null +++ b/meson/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/meson/test cases/d/4 library versions/meson.build b/meson/test cases/d/4 library versions/meson.build new file mode 100644 index 000000000..c745b9227 --- /dev/null +++ b/meson/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/meson/test cases/d/4 library versions/test.json b/meson/test cases/d/4 library versions/test.json new file mode 100644 index 000000000..23c95dd52 --- /dev/null +++ b/meson/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/meson/test cases/d/5 mixed/app.d b/meson/test cases/d/5 mixed/app.d new file mode 100644 index 000000000..6ab5d97d6 --- /dev/null +++ b/meson/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/meson/test cases/d/5 mixed/libstuff.c b/meson/test cases/d/5 mixed/libstuff.c new file mode 100644 index 000000000..92d6600ce --- /dev/null +++ b/meson/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/meson/test cases/d/5 mixed/meson.build b/meson/test cases/d/5 mixed/meson.build new file mode 100644 index 000000000..3dad66d0c --- /dev/null +++ b/meson/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/meson/test cases/d/5 mixed/test.json b/meson/test cases/d/5 mixed/test.json new file mode 100644 index 000000000..c95d0ca0c --- /dev/null +++ b/meson/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/meson/test cases/d/6 unittest/app.d b/meson/test cases/d/6 unittest/app.d new file mode 100644 index 000000000..71c641415 --- /dev/null +++ b/meson/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/meson/test cases/d/6 unittest/meson.build b/meson/test cases/d/6 unittest/meson.build new file mode 100644 index 000000000..49a070047 --- /dev/null +++ b/meson/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/meson/test cases/d/6 unittest/second_unit.d b/meson/test cases/d/6 unittest/second_unit.d new file mode 100644 index 000000000..fdb62a918 --- /dev/null +++ b/meson/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/meson/test cases/d/6 unittest/test.json b/meson/test cases/d/6 unittest/test.json new file mode 100644 index 000000000..adc4d75a1 --- /dev/null +++ b/meson/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/meson/test cases/d/7 multilib/app.d b/meson/test cases/d/7 multilib/app.d new file mode 100644 index 000000000..892596ad9 --- /dev/null +++ b/meson/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/meson/test cases/d/7 multilib/meson.build b/meson/test cases/d/7 multilib/meson.build new file mode 100644 index 000000000..1879c083f --- /dev/null +++ b/meson/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/meson/test cases/d/7 multilib/say1.d b/meson/test cases/d/7 multilib/say1.d new file mode 100644 index 000000000..605fd2355 --- /dev/null +++ b/meson/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/meson/test cases/d/7 multilib/say1.di b/meson/test cases/d/7 multilib/say1.di new file mode 100644 index 000000000..8a9ff02da --- /dev/null +++ b/meson/test cases/d/7 multilib/say1.di @@ -0,0 +1 @@ +int sayHello1 (string str); diff --git a/meson/test cases/d/7 multilib/say2.d b/meson/test cases/d/7 multilib/say2.d new file mode 100644 index 000000000..7270ebd22 --- /dev/null +++ b/meson/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/meson/test cases/d/7 multilib/say2.di b/meson/test cases/d/7 multilib/say2.di new file mode 100644 index 000000000..da712f0de --- /dev/null +++ b/meson/test cases/d/7 multilib/say2.di @@ -0,0 +1 @@ +int sayHello2 (string str); diff --git a/meson/test cases/d/7 multilib/test.json b/meson/test cases/d/7 multilib/test.json new file mode 100644 index 000000000..5944ae0e1 --- /dev/null +++ b/meson/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/meson/test cases/d/8 has multi arguments/meson.build b/meson/test cases/d/8 has multi arguments/meson.build new file mode 100644 index 000000000..08970572c --- /dev/null +++ b/meson/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/meson/test cases/d/9 features/app.d b/meson/test cases/d/9 features/app.d new file mode 100644 index 000000000..05c56ca5f --- /dev/null +++ b/meson/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/meson/test cases/d/9 features/data/food.txt b/meson/test cases/d/9 features/data/food.txt new file mode 100644 index 000000000..8275dd02c --- /dev/null +++ b/meson/test cases/d/9 features/data/food.txt @@ -0,0 +1,6 @@ +Spam +Eggs +Spam +Baked Beans +Spam +Spam diff --git a/meson/test cases/d/9 features/data/people.txt b/meson/test cases/d/9 features/data/people.txt new file mode 100644 index 000000000..abbae060b --- /dev/null +++ b/meson/test cases/d/9 features/data/people.txt @@ -0,0 +1,5 @@ +Rick +Morty +Summer +Beth +Jerry diff --git a/meson/test cases/d/9 features/extra.d b/meson/test cases/d/9 features/extra.d new file mode 100644 index 000000000..832b29207 --- /dev/null +++ b/meson/test cases/d/9 features/extra.d @@ -0,0 +1,9 @@ + +auto secondModulePeopleVersionSet () +{ + version (With_People) { + return true; + } else { + return false; + } +} diff --git a/meson/test cases/d/9 features/meson.build b/meson/test cases/d/9 features/meson.build new file mode 100644 index 000000000..06f03414d --- /dev/null +++ b/meson/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']) |