Skip to content

Commit 3ccac40

Browse files
committed
Add new testing crate to test rustest from an external crate.
`rustest-testing` is not intended to be published.
1 parent 260054e commit 3ccac40

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["rustest", "rustest-macro"]
2+
members = ["rustest", "rustest-macro", "rustest-testing"]
33
resolver = "2"
44

55
[workspace.package]

Diff for: rustest-testing/Cargo.toml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "rustest-testing"
3+
edition.workspace = true
4+
version.workspace = true
5+
authors.workspace = true
6+
repository.workspace = true
7+
homepage.workspace = true
8+
license.workspace = true
9+
description.workspace = true
10+
keywords.workspace = true
11+
categories.workspace = true
12+
13+
[dependencies]
14+
15+
[dev-dependencies]
16+
rustest = { path = "../rustest" }
17+
18+
19+
[lib]
20+
harness = false

Diff for: rustest-testing/src/lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
mod other_mod;
2+
3+
pub use other_mod::*;
4+
5+
pub fn add(left: u64, right: u64) -> u64 {
6+
left + right
7+
}
8+
9+
#[cfg(test)]
10+
mod tests {
11+
use super::*;
12+
use rustest::test;
13+
14+
#[test]
15+
fn it_works() {
16+
let result = add(2, 2);
17+
assert!(result == 4);
18+
}
19+
}
20+
21+
#[cfg(test)]
22+
#[rustest::main]
23+
fn main() {}

Diff for: rustest-testing/src/other_mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
pub fn addition(a: u32, b: u32) -> u32 {
2+
a + b
3+
}
4+
5+
#[cfg(test)]
6+
pub(crate) mod tests {
7+
use super::*;
8+
use rustest::test;
9+
10+
#[test(params:(u32, u32, u32)=[
11+
(1,2,3),
12+
(5,6,11),
13+
(598318, 54876521, 55474839)
14+
])]
15+
fn test_addition_ok(Param((a, b, expected)): Param) {
16+
assert_eq!(addition(a, b), expected);
17+
}
18+
19+
#[test(params:(u32, u32, u32)=[
20+
(1,2,4),
21+
(5,6,5555),
22+
(598318, 54876521, 0)
23+
])]
24+
#[xfail]
25+
fn test_addition_fail(Param((a, b, expected)): Param) {
26+
assert_eq!(addition(a, b), expected);
27+
}
28+
}

0 commit comments

Comments
 (0)