aboutsummaryrefslogtreecommitdiff
path: root/test cases
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-10-21 16:07:31 -0700
committerDylan Baker <dylan@pnwbakers.com>2021-01-05 15:10:50 -0800
commit3d80a88bd3c3dc8f9e20bbda485b0b436fd79fb3 (patch)
treed8c4fe8fd2c76920a42e4090348681169974f2af /test cases
parentb2c2549b93a8001d8a6d9d6da1ce756645e59160 (diff)
downloadmeson-3d80a88bd3c3dc8f9e20bbda485b0b436fd79fb3.zip
meson-3d80a88bd3c3dc8f9e20bbda485b0b436fd79fb3.tar.gz
meson-3d80a88bd3c3dc8f9e20bbda485b0b436fd79fb3.tar.bz2
modules: Add an unstable-rust module
Like other language specific modules this module is module for holding rust specific helpers. This commit adds a test() function, which simplifies using rust's internal unittest mechanism. Rust tests are generally placed in the same code files as they are testing, in contrast to languages like C/C++ and python which generally place the tests in separate translation units. For meson this is somewhat problematic from a repetition point of view, as the only changes are generally adding --test, and possibly some dependencies. The rustmod.test() method provides a mechanism to remove the repatition: it takes a rust target, copies it, and then addes the `--test` option, then creates a Test() target with the `rust` protocol. You can pass additional dependencies via the `dependencies` keyword. This all makes for a nice, DRY, test definition.
Diffstat (limited to 'test cases')
-rw-r--r--test cases/rust/9 unit tests/meson.build11
-rw-r--r--test cases/rust/9 unit tests/test2.rs11
2 files changed, 22 insertions, 0 deletions
diff --git a/test cases/rust/9 unit tests/meson.build b/test cases/rust/9 unit tests/meson.build
index 44fd6b6..b649abb 100644
--- a/test cases/rust/9 unit tests/meson.build
+++ b/test cases/rust/9 unit tests/meson.build
@@ -30,3 +30,14 @@ test(
protocol : 'rust',
suite : ['foo'],
)
+
+exe = executable('rust_exe', ['test2.rs', 'test.rs'])
+
+rust = import('unstable-rust')
+rust.test('rust_test_from_exe', exe, should_fail : true)
+
+lib = static_library('rust_static', ['test.rs'])
+rust.test('rust_test_from_static', lib, args: ['--skip', 'test_add_intentional_fail'])
+
+lib = shared_library('rust_shared', ['test.rs'])
+rust.test('rust_test_from_shared', lib, args: ['--skip', 'test_add_intentional_fail'])
diff --git a/test cases/rust/9 unit tests/test2.rs b/test cases/rust/9 unit tests/test2.rs
new file mode 100644
index 0000000..9623c7c
--- /dev/null
+++ b/test cases/rust/9 unit tests/test2.rs
@@ -0,0 +1,11 @@
+mod test;
+use std::env;
+
+fn main() {
+ let args: Vec<String> = env::args().collect();
+ let first = args[1].parse::<i32>().expect("Invliad value for first argument.");
+ let second = args[2].parse::<i32>().expect("Invliad value for second argument.");
+
+ let new = test::add(first, second);
+ println!("New value: {}", new);
+}