diff options
| author | Matthias Klumpp <matthias@tenstral.net> | 2016-08-19 03:04:51 +0200 |
|---|---|---|
| committer | Matthias Klumpp <matthias@tenstral.net> | 2016-08-20 18:48:28 +0200 |
| commit | 57c54a678c8eec18df345a44075d59f6384be8f0 (patch) | |
| tree | a98c03f4d722eeb341b3465e9b5de11c35d66840 /test cases | |
| parent | 3eb90414f62f857abbb1c62e8e4c823b7b1473e6 (diff) | |
| download | meson-57c54a678c8eec18df345a44075d59f6384be8f0.tar.gz | |
Allow build definitions to retrieve the unittest flag of a D compiler
D allows programmers to define their tests alongside the actual code in
a unittest scope[1].
When compiled with a special flag, the compiler will build a binary
containing the tests instead of the actual application.
This is a strightforward and easy way to run tests and works well with
Mesons test() command.
Since using just one flag name to enable unittest mode would be too
boring, compiler developers invented multiple ones.
Adding this helper method makes it easy for people writing Meson build
descriptions for D projects to enable unittestmode.
[1]: https://dlang.org/spec/unittest.html
Diffstat (limited to 'test cases')
| -rw-r--r-- | test cases/d/4 unittest/app.d | 34 | ||||
| -rw-r--r-- | test cases/d/4 unittest/installed_files.txt | 1 | ||||
| -rw-r--r-- | test cases/d/4 unittest/meson.build | 8 |
3 files changed, 43 insertions, 0 deletions
diff --git a/test cases/d/4 unittest/app.d b/test cases/d/4 unittest/app.d new file mode 100644 index 000000000..751e754d6 --- /dev/null +++ b/test cases/d/4 unittest/app.d @@ -0,0 +1,34 @@ + +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; + + assert (getFour () > 2); + assert (getFour () == 4); + + // 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/4 unittest/installed_files.txt b/test cases/d/4 unittest/installed_files.txt new file mode 100644 index 000000000..e718389c8 --- /dev/null +++ b/test cases/d/4 unittest/installed_files.txt @@ -0,0 +1 @@ +usr/bin/dapp?exe diff --git a/test cases/d/4 unittest/meson.build b/test cases/d/4 unittest/meson.build new file mode 100644 index 000000000..ca39adfba --- /dev/null +++ b/test cases/d/4 unittest/meson.build @@ -0,0 +1,8 @@ +project('D Unittests', 'd') + +e = executable('dapp', 'app.d', install : true) +test('dapp_run', e, should_fail: true) + +e_test = executable('dapp_test', 'app.d', + d_args: meson.get_compiler('d').get_unittest_flag()) +test('dapp_test', e_test) |
