Skip to content

Commit ec23144

Browse files
committed
LLVM-based coverage.
Also fixed a test that left output in the root directory
1 parent 974f417 commit ec23144

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

build.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
fn main() {
22
// This is needed to be able to test the println! output that some code produces
33
println!("cargo:rustc-env=RUST_TEST_NOCAPTURE=1");
4-
5-
// // This is needed to avoid multiple tests to concurrently capture stdout
6-
// println!("cargo:rustc-env=RUST_TEST_THREADS=1");
74
}

code-coverage.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
cargo tarpaulin -o Html
1+
GRCOV_DIR=~/apps/grcov
2+
echo Directory containing the grcov executable: $GRCOV_DIR
3+
4+
cargo clean
5+
6+
echo Run tests producing raw coverage data...
7+
CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test
8+
9+
echo Execute grcov to collect coverage data and produce HTML report...
10+
$GRCOV_DIR/grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage/html
11+
12+
echo Deleting the *.profraw files from the current directory
13+
rm *.profraw
14+
15+
open target/coverage/html/index.html
16+

src/bin/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ fn real_main(args: Cli) -> i32 {
8686
XMLUtil::grep_xml(&temp_dir, &src_file, &grep_args.regex)
8787
},
8888
Commands::Replace(replace_args) => {
89+
// let x = replace_args.out_file.as_deref();
90+
8991
XMLUtil::replace_xml(&temp_dir, &src_file,
9092
&replace_args.regex, &replace_args.replace,
91-
&replace_args.out_file);
93+
&replace_args.out_file.as_deref());
9294
},
9395
Commands::ReplaceLinks(replace_args) => {
9496
XMLUtil::replace_attr(&temp_dir, &src_file,
9597
&replace_args.regex, &replace_args.replace,
96-
&replace_args.out_file);
98+
&replace_args.out_file.as_deref());
9799
}
98100
}
99101

src/xml_util.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ impl XMLUtil {
2828
Self::snr_xml(Mode::Value, dir, src_file, None, Some(pattern), None, None);
2929
}
3030

31-
pub fn replace_xml(dir: &str, src_file: &str, pattern: &str, replace: &str, output_file: &Option<String>) {
31+
pub fn replace_xml(dir: &str, src_file: &str, pattern: &str, replace: &str, output_file: &Option<&str>) {
3232
let out_file = match output_file {
33-
Some(of) => of.as_str(),
33+
Some(of) => of,
3434
None => src_file
3535
};
3636

3737
Self::snr_xml(Mode::Value, dir, src_file, Some(vec!("word/document.xml")), Some(pattern), Some(replace), Some(out_file));
3838
}
3939

40-
pub fn replace_attr(dir: &str, src_file: &str, pattern: &str, replace: &str, output_file: &Option<String>) {
40+
pub fn replace_attr(dir: &str, src_file: &str, pattern: &str, replace: &str, output_file: &Option<&str>) {
4141
let out_file = match output_file {
42-
Some(of) => of.as_str(),
42+
Some(of) => of,
4343
None => src_file
4444
};
4545

@@ -251,7 +251,8 @@ mod tests {
251251
assert!(!before.contains("zzz"), "Precondition");
252252

253253
XMLUtil::replace_xml(&testdir.to_string_lossy(), "my-source.docx",
254-
"[Ss]ome", "zzz", &None);
254+
"[Ss]ome", "zzz",
255+
&Some(&testdir.join("output.docx").to_string_lossy()));
255256

256257
// Check that the replacement worked as expected
257258
let after = fs::read_to_string(testdir.join("word/document.xml"))?;
@@ -279,7 +280,8 @@ mod tests {
279280
assert!(before_doc.contains(">www.example.com<"), "Precondition");
280281

281282
XMLUtil::replace_attr(&testdir.to_string_lossy(), "my-source.docx",
282-
"www.example.com", "foobar.org", &None);
283+
"www.example.com", "foobar.org",
284+
&Some(&testdir.join("output-2.docx").to_string_lossy()));
283285

284286
let after_doc = fs::read_to_string("./src/test/test_tree2/word/document.xml")?;
285287
let after = fs::read_to_string(testdir.join("word/_rels/document.xml.rels"))?;

0 commit comments

Comments
 (0)