diff options
Diffstat (limited to '')
-rw-r--r-- | test cases/rust/9 unit tests/meson.build | 43 | ||||
-rw-r--r-- | test cases/rust/9 unit tests/test.rs | 24 | ||||
-rw-r--r-- | test cases/rust/9 unit tests/test2.rs | 11 |
3 files changed, 78 insertions, 0 deletions
diff --git a/test cases/rust/9 unit tests/meson.build b/test cases/rust/9 unit tests/meson.build new file mode 100644 index 0000000..b649abb --- /dev/null +++ b/test cases/rust/9 unit tests/meson.build @@ -0,0 +1,43 @@ +project('rust unit tests', 'rust') + +t = executable( + 'rust_test', + ['test.rs'], + rust_args : ['--test'], +) + +test( + 'rust test (should fail)', + t, + protocol : 'rust', + suite : ['foo'], + should_fail : true, +) + +test( + 'rust test (should pass)', + t, + args : ['--skip', 'test_add_intentional_fail'], + protocol : 'rust', + suite : ['foo'], +) + + +test( + 'rust test (should skip)', + t, + args : ['--skip', 'test_add'], + 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/test.rs b/test cases/rust/9 unit tests/test.rs new file mode 100644 index 0000000..0225be5 --- /dev/null +++ b/test cases/rust/9 unit tests/test.rs @@ -0,0 +1,24 @@ +pub fn add(a: i32, b: i32) -> i32 { + return a + b; +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_add() { + assert_eq!(add(1, 2), 3); + } + + #[test] + fn test_add_intentional_fail() { + assert_eq!(add(1, 2), 5); + } + + #[test] + #[ignore] + fn test_add_intentional_fail2() { + assert_eq!(add(1, 7), 5); + } +} 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); +} |