aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/compilers.py6
-rw-r--r--mesonbuild/interpreter.py7
-rw-r--r--test cases/d/4 unittest/app.d34
-rw-r--r--test cases/d/4 unittest/installed_files.txt1
-rw-r--r--test cases/d/4 unittest/meson.build8
5 files changed, 56 insertions, 0 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 88184cb..450e8a5 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -1505,6 +1505,9 @@ class DCompiler(Compiler):
def get_soname_args(self, shlib_name, path, soversion):
return []
+ def get_unittest_flag(self):
+ return ['-unittest']
+
def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
# This method is to be used by LDC and DMD.
# GDC can deal with the verbatim flags.
@@ -1562,6 +1565,9 @@ class GnuDCompiler(DCompiler):
def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
return build_unix_rpath_args(build_dir, rpath_paths, install_rpath)
+ def get_unittest_flag(self):
+ return ['-funittest']
+
class LLVMDCompiler(DCompiler):
def __init__(self, exelist, version, is_cross):
DCompiler.__init__(self, exelist, version, is_cross)
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 5a6d702..763eb7d 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -597,6 +597,7 @@ class CompilerHolder(InterpreterObject):
'find_library': self.find_library_method,
'has_argument' : self.has_argument_method,
'first_supported_argument' : self.first_supported_argument_method,
+ 'get_unittest_flag' : self.get_unittest_flag_method,
})
def version_method(self, args, kwargs):
@@ -650,6 +651,12 @@ class CompilerHolder(InterpreterObject):
def get_id_method(self, args, kwargs):
return self.compiler.get_id()
+ def get_unittest_flag_method(self, args, kwargs):
+ # At time, only D compilers have this feature.
+ if not getattr(self.compiler, "get_unittest_flag", None):
+ return ''
+ return self.compiler.get_unittest_flag()
+
def has_member_method(self, args, kwargs):
if len(args) != 2:
raise InterpreterException('Has_member takes exactly two arguments.')
diff --git a/test cases/d/4 unittest/app.d b/test cases/d/4 unittest/app.d
new file mode 100644
index 0000000..751e754
--- /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 0000000..e718389
--- /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 0000000..ca39adf
--- /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)