Skip to content

Commit f2d5688

Browse files
committed
add options to pass features in mutagen runner
1 parent 99d9e12 commit f2d5688

File tree

6 files changed

+61
-4
lines changed

6 files changed

+61
-4
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ script:
1313

1414
# run executable cargo-mutagen on test project
1515
- pushd examples/simple
16-
- cargo run --bin cargo-mutagen --package cargo-mutagen
16+
- cargo run --package cargo-mutagen
17+
- popd
18+
- pushd examples/feature-gated
19+
- cargo run --package cargo-mutagen -- --features with_mutagen

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"mutagen-transform",
77
"mutagen-selftest",
88
"examples/simple",
9+
"examples/feature-gated",
910
"examples/with-integration-tests-v1",
1011
"examples/with-integration-tests-v2",
1112
]

examples/feature-gated/Cargo.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "feature-gated"
3+
version = "0.2.0"
4+
authors = ["Samuel Pilz <[email protected]>"]
5+
edition = "2018"
6+
7+
[dev-dependencies]
8+
mutagen = {path = "../../mutagen"}
9+
10+
[lib]
11+
doctest = false
12+
13+
[features]
14+
with_mutagen = []
15+

examples/feature-gated/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[cfg_attr(all(test, feature = "with_mutagen"), ::mutagen::mutate)]
2+
pub fn foo() -> i32 {
3+
1 + 2
4+
}
5+
6+
#[cfg(test)]
7+
mod tests {
8+
use super::foo;
9+
10+
#[test]
11+
fn test_foo() {
12+
assert_eq!(foo(), 3);
13+
}
14+
}

mutagen-runner/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-mutagen"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["Andre Bogus <[email protected]>", "Samuel Pilz <[email protected]>"]
55
edition = "2018"
66

@@ -12,6 +12,7 @@ serde_json = "1.0"
1212
mutagen-core = { path = "../mutagen-core"}
1313
console = "0.9.1"
1414
humantime = "2.0.0"
15+
structopt = "0.3"
1516

1617
[badges]
1718
travis-ci = { repository = "llogiq/mutagen", branch = "master" }

mutagen-runner/src/main.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,25 @@ fn main() {
2121
}
2222
}
2323

24+
use structopt::StructOpt;
25+
#[derive(StructOpt, Debug)]
26+
struct Options {
27+
/// Space-separated list of features to activate
28+
#[structopt(long, name = "FEATURES")]
29+
features: Option<String>,
30+
31+
/// Activate all available features
32+
#[structopt(long)]
33+
all_features: bool,
34+
}
35+
2436
fn run() -> Fallible<()> {
2537
let mutagen_start = Instant::now();
2638

39+
let opt = Options::from_args();
40+
2741
// build the testsuites and collect mutations
28-
let test_bins = compile_tests()?;
42+
let test_bins = compile_tests(&opt)?;
2943
if test_bins.is_empty() {
3044
bail!("no test executable(s) found");
3145
}
@@ -102,12 +116,21 @@ fn run_mutations(
102116
}
103117

104118
/// build all tests and collect test-suite executables
105-
fn compile_tests() -> Fallible<Vec<PathBuf>> {
119+
fn compile_tests(opt: &Options) -> Fallible<Vec<PathBuf>> {
106120
let mut tests: Vec<PathBuf> = Vec::new();
107121

122+
let mut feature_args: Vec<&str> = vec![];
123+
if let Some(f) = &opt.features {
124+
feature_args.extend(&["--features", f]);
125+
}
126+
if opt.all_features {
127+
feature_args.push("--all-features");
128+
}
129+
108130
// execute `cargo test --no-run --message-format=json` and collect output
109131
let compile_out = Command::new("cargo")
110132
.args(&["test", "--no-run", "--message-format=json"])
133+
.args(&feature_args)
111134
.stderr(Stdio::inherit())
112135
.output()?;
113136
if !compile_out.status.success() {

0 commit comments

Comments
 (0)