From 7ebbda7fd71495b6f4e9bf87d385d19c44102c62 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 23 Dec 2021 20:02:54 -0500 Subject: fix(coverage): use only string byte indexes and 0-indexed line numbers (#13190) --- cli/tests/integration/coverage_tests.rs | 95 ++++------------------ cli/tests/testdata/coverage/branch_expected.lcov | 27 ++++++ cli/tests/testdata/coverage/branch_expected.out | 11 +++ cli/tests/testdata/coverage/complex_expected.lcov | 53 ++++++++++++ cli/tests/testdata/coverage/complex_expected.out | 19 +++++ cli/tests/testdata/coverage/expected_branch.lcov | 27 ------ cli/tests/testdata/coverage/expected_branch.out | 12 --- cli/tests/testdata/coverage/expected_complex.lcov | 53 ------------ cli/tests/testdata/coverage/expected_complex.out | 19 ----- cli/tests/testdata/coverage/final_blankline.js | 5 ++ .../coverage/final_blankline_expected.lcov | 16 ++++ .../testdata/coverage/final_blankline_expected.out | 1 + .../testdata/coverage/final_blankline_test.js | 5 ++ 13 files changed, 154 insertions(+), 189 deletions(-) create mode 100644 cli/tests/testdata/coverage/branch_expected.lcov create mode 100644 cli/tests/testdata/coverage/branch_expected.out create mode 100644 cli/tests/testdata/coverage/complex_expected.lcov create mode 100644 cli/tests/testdata/coverage/complex_expected.out delete mode 100644 cli/tests/testdata/coverage/expected_branch.lcov delete mode 100644 cli/tests/testdata/coverage/expected_branch.out delete mode 100644 cli/tests/testdata/coverage/expected_complex.lcov delete mode 100644 cli/tests/testdata/coverage/expected_complex.out create mode 100644 cli/tests/testdata/coverage/final_blankline.js create mode 100644 cli/tests/testdata/coverage/final_blankline_expected.lcov create mode 100644 cli/tests/testdata/coverage/final_blankline_expected.out create mode 100644 cli/tests/testdata/coverage/final_blankline_test.js (limited to 'cli/tests') diff --git a/cli/tests/integration/coverage_tests.rs b/cli/tests/integration/coverage_tests.rs index 4580b5cec..2f7250817 100644 --- a/cli/tests/integration/coverage_tests.rs +++ b/cli/tests/integration/coverage_tests.rs @@ -6,90 +6,29 @@ use test_util as util; #[test] fn branch() { - let tempdir = TempDir::new().expect("tempdir fail"); - let tempdir = tempdir.path().join("cov"); - let status = util::deno_cmd() - .current_dir(util::testdata_path()) - .arg("test") - .arg("--quiet") - .arg("--unstable") - .arg(format!("--coverage={}", tempdir.to_str().unwrap())) - .arg("coverage/branch_test.ts") - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::inherit()) - .status() - .expect("failed to spawn test runner"); - - assert!(status.success()); - - let output = util::deno_cmd() - .current_dir(util::testdata_path()) - .arg("coverage") - .arg("--quiet") - .arg("--unstable") - .arg(format!("{}/", tempdir.to_str().unwrap())) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::inherit()) - .output() - .expect("failed to spawn coverage reporter"); - - let actual = - util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap()) - .to_string(); - - let expected = fs::read_to_string( - util::testdata_path().join("coverage/expected_branch.out"), - ) - .unwrap(); - - if !util::wildcard_match(&expected, &actual) { - println!("OUTPUT\n{}\nOUTPUT", actual); - println!("EXPECTED\n{}\nEXPECTED", expected); - panic!("pattern match failed"); - } - - assert!(output.status.success()); - - let output = util::deno_cmd() - .current_dir(util::testdata_path()) - .arg("coverage") - .arg("--quiet") - .arg("--unstable") - .arg("--lcov") - .arg(format!("{}/", tempdir.to_str().unwrap())) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::inherit()) - .output() - .expect("failed to spawn coverage reporter"); - - let actual = - util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap()) - .to_string(); - - let expected = fs::read_to_string( - util::testdata_path().join("coverage/expected_branch.lcov"), - ) - .unwrap(); - - if !util::wildcard_match(&expected, &actual) { - println!("OUTPUT\n{}\nOUTPUT", actual); - println!("EXPECTED\n{}\nEXPECTED", expected); - panic!("pattern match failed"); - } - - assert!(output.status.success()); + run_coverage_text("branch", "ts"); } #[test] fn complex() { + run_coverage_text("complex", "ts"); +} + +#[test] +fn final_blankline() { + run_coverage_text("final_blankline", "js"); +} + +fn run_coverage_text(test_name: &str, extension: &str) { let tempdir = TempDir::new().expect("tempdir fail"); + let tempdir = tempdir.path().join("cov"); let status = util::deno_cmd() .current_dir(util::testdata_path()) .arg("test") .arg("--quiet") .arg("--unstable") - .arg(format!("--coverage={}", tempdir.path().to_str().unwrap())) - .arg("coverage/complex_test.ts") + .arg(format!("--coverage={}", tempdir.to_str().unwrap())) + .arg(format!("coverage/{}_test.{}", test_name, extension)) .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::inherit()) .status() @@ -102,7 +41,7 @@ fn complex() { .arg("coverage") .arg("--quiet") .arg("--unstable") - .arg(format!("{}/", tempdir.path().to_str().unwrap())) + .arg(format!("{}/", tempdir.to_str().unwrap())) .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::inherit()) .output() @@ -113,7 +52,7 @@ fn complex() { .to_string(); let expected = fs::read_to_string( - util::testdata_path().join("coverage/expected_complex.out"), + util::testdata_path().join(format!("coverage/{}_expected.out", test_name)), ) .unwrap(); @@ -131,7 +70,7 @@ fn complex() { .arg("--quiet") .arg("--unstable") .arg("--lcov") - .arg(format!("{}/", tempdir.path().to_str().unwrap())) + .arg(format!("{}/", tempdir.to_str().unwrap())) .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::inherit()) .output() @@ -142,7 +81,7 @@ fn complex() { .to_string(); let expected = fs::read_to_string( - util::testdata_path().join("coverage/expected_complex.lcov"), + util::testdata_path().join(format!("coverage/{}_expected.lcov", test_name)), ) .unwrap(); diff --git a/cli/tests/testdata/coverage/branch_expected.lcov b/cli/tests/testdata/coverage/branch_expected.lcov new file mode 100644 index 000000000..31da70224 --- /dev/null +++ b/cli/tests/testdata/coverage/branch_expected.lcov @@ -0,0 +1,27 @@ +SF:[WILDCARD]branch.ts +FN:1,branch +FN:9,unused +FNDA:1,branch +FNDA:0,unused +FNF:2 +FNH:1 +BRDA:4,1,0,0 +BRF:1 +BRH:0 +DA:1,1 +DA:2,2 +DA:3,2 +DA:4,2 +DA:5,0 +DA:6,0 +DA:7,2 +DA:9,0 +DA:10,0 +DA:11,0 +DA:12,0 +DA:13,0 +DA:14,0 +DA:15,0 +LH:5 +LF:14 +end_of_record diff --git a/cli/tests/testdata/coverage/branch_expected.out b/cli/tests/testdata/coverage/branch_expected.out new file mode 100644 index 000000000..2ff5e911e --- /dev/null +++ b/cli/tests/testdata/coverage/branch_expected.out @@ -0,0 +1,11 @@ +cover [WILDCARD]/coverage/branch.ts ... 35.714% (5/14) + 5 | return false; + 6 | } +-----|----- + 9 | export function unused(condition: boolean): boolean { + 10 | if (condition) { + 11 | return false; + 12 | } else { + 13 | return true; + 14 | } + 15 | } diff --git a/cli/tests/testdata/coverage/complex_expected.lcov b/cli/tests/testdata/coverage/complex_expected.lcov new file mode 100644 index 000000000..a0af4cff3 --- /dev/null +++ b/cli/tests/testdata/coverage/complex_expected.lcov @@ -0,0 +1,53 @@ +SF:[WILDCARD]complex.ts +FN:17,dependency +FN:32,complex +FN:46,unused +FN:64,ƒ +FNDA:1,dependency +FNDA:1,complex +FNDA:0,unused +FNDA:0,ƒ +FNF:4 +FNH:2 +BRF:0 +BRH:0 +DA:17,2 +DA:18,2 +DA:19,2 +DA:20,2 +DA:22,2 +DA:23,2 +DA:24,2 +DA:25,2 +DA:26,2 +DA:27,2 +DA:32,1 +DA:33,1 +DA:34,1 +DA:35,1 +DA:37,2 +DA:38,2 +DA:39,2 +DA:40,2 +DA:41,2 +DA:42,2 +DA:46,0 +DA:47,0 +DA:48,0 +DA:49,0 +DA:51,0 +DA:52,0 +DA:53,0 +DA:54,0 +DA:55,0 +DA:56,0 +DA:60,1 +DA:64,0 +DA:65,0 +DA:66,0 +DA:67,0 +DA:68,1 +DA:71,0 +LH:22 +LF:37 +end_of_record diff --git a/cli/tests/testdata/coverage/complex_expected.out b/cli/tests/testdata/coverage/complex_expected.out new file mode 100644 index 000000000..e9f9a453f --- /dev/null +++ b/cli/tests/testdata/coverage/complex_expected.out @@ -0,0 +1,19 @@ +cover [WILDCARD]/coverage/complex.ts ... 59.459% (22/37) + 46 | export function unused( + 47 | foo: string, + 48 | bar: string, + 49 | baz: string, +-----|----- + 51 | return complex( + 52 | foo, + 53 | bar, + 54 | baz, + 55 | ); + 56 | } +-----|----- + 64 | export function ƒ(): number { + 65 | return ( + 66 | 0 + 67 | ); +-----|----- + 71 | console.log("%s", () => 1); diff --git a/cli/tests/testdata/coverage/expected_branch.lcov b/cli/tests/testdata/coverage/expected_branch.lcov deleted file mode 100644 index 07e29cca5..000000000 --- a/cli/tests/testdata/coverage/expected_branch.lcov +++ /dev/null @@ -1,27 +0,0 @@ -SF:[WILDCARD]branch.ts -FN:2,branch -FN:10,unused -FNDA:1,branch -FNDA:0,unused -FNF:2 -FNH:1 -BRDA:4,1,0,0 -BRF:1 -BRH:0 -DA:1,1 -DA:2,2 -DA:3,2 -DA:4,0 -DA:5,0 -DA:6,0 -DA:7,1 -DA:9,0 -DA:10,0 -DA:11,0 -DA:12,0 -DA:13,0 -DA:14,0 -DA:15,0 -LH:4 -LF:14 -end_of_record diff --git a/cli/tests/testdata/coverage/expected_branch.out b/cli/tests/testdata/coverage/expected_branch.out deleted file mode 100644 index 630ea93b2..000000000 --- a/cli/tests/testdata/coverage/expected_branch.out +++ /dev/null @@ -1,12 +0,0 @@ -cover [WILDCARD]/coverage/branch.ts ... 28.571% (4/14) - 4 | } else { - 5 | return false; - 6 | } ------|----- - 9 | export function unused(condition: boolean): boolean { - 10 | if (condition) { - 11 | return false; - 12 | } else { - 13 | return true; - 14 | } - 15 | } diff --git a/cli/tests/testdata/coverage/expected_complex.lcov b/cli/tests/testdata/coverage/expected_complex.lcov deleted file mode 100644 index 962ebee96..000000000 --- a/cli/tests/testdata/coverage/expected_complex.lcov +++ /dev/null @@ -1,53 +0,0 @@ -SF:[WILDCARD]complex.ts -FN:22,dependency -FN:37,complex -FN:51,unused -FN:65,ƒ -FNDA:1,dependency -FNDA:1,complex -FNDA:0,unused -FNDA:0,ƒ -FNF:4 -FNH:2 -BRF:0 -BRH:0 -DA:17,2 -DA:18,2 -DA:19,2 -DA:20,2 -DA:22,2 -DA:23,2 -DA:24,2 -DA:25,2 -DA:26,2 -DA:27,1 -DA:32,1 -DA:33,1 -DA:34,1 -DA:35,1 -DA:37,2 -DA:38,2 -DA:39,2 -DA:40,2 -DA:41,2 -DA:42,1 -DA:46,0 -DA:47,0 -DA:48,0 -DA:49,0 -DA:51,0 -DA:52,0 -DA:53,0 -DA:54,0 -DA:55,0 -DA:56,0 -DA:60,1 -DA:64,0 -DA:65,0 -DA:66,0 -DA:67,0 -DA:68,1 -DA:71,0 -LH:22 -LF:37 -end_of_record diff --git a/cli/tests/testdata/coverage/expected_complex.out b/cli/tests/testdata/coverage/expected_complex.out deleted file mode 100644 index e9f9a453f..000000000 --- a/cli/tests/testdata/coverage/expected_complex.out +++ /dev/null @@ -1,19 +0,0 @@ -cover [WILDCARD]/coverage/complex.ts ... 59.459% (22/37) - 46 | export function unused( - 47 | foo: string, - 48 | bar: string, - 49 | baz: string, ------|----- - 51 | return complex( - 52 | foo, - 53 | bar, - 54 | baz, - 55 | ); - 56 | } ------|----- - 64 | export function ƒ(): number { - 65 | return ( - 66 | 0 - 67 | ); ------|----- - 71 | console.log("%s", () => 1); diff --git a/cli/tests/testdata/coverage/final_blankline.js b/cli/tests/testdata/coverage/final_blankline.js new file mode 100644 index 000000000..bb5ab0378 --- /dev/null +++ b/cli/tests/testdata/coverage/final_blankline.js @@ -0,0 +1,5 @@ +// deno-fmt-ignore-file - has blankline at end +export default function example() { + return true; +} + diff --git a/cli/tests/testdata/coverage/final_blankline_expected.lcov b/cli/tests/testdata/coverage/final_blankline_expected.lcov new file mode 100644 index 000000000..48af66180 --- /dev/null +++ b/cli/tests/testdata/coverage/final_blankline_expected.lcov @@ -0,0 +1,16 @@ +SF:[WILDCARD]final_blankline.js +FN:2,example +FNDA:1,example +FNF:1 +FNH:1 +BRF:0 +BRH:0 +DA:1,1 +DA:2,1 +DA:3,2 +DA:4,2 +DA:5,1 +DA:6,1 +LH:6 +LF:6 +end_of_record diff --git a/cli/tests/testdata/coverage/final_blankline_expected.out b/cli/tests/testdata/coverage/final_blankline_expected.out new file mode 100644 index 000000000..8dc5ce30d --- /dev/null +++ b/cli/tests/testdata/coverage/final_blankline_expected.out @@ -0,0 +1 @@ +cover file:///[WILDCARD]final_blankline.js ... 100.000% (6/6) diff --git a/cli/tests/testdata/coverage/final_blankline_test.js b/cli/tests/testdata/coverage/final_blankline_test.js new file mode 100644 index 000000000..e7331c537 --- /dev/null +++ b/cli/tests/testdata/coverage/final_blankline_test.js @@ -0,0 +1,5 @@ +import example from "./final_blankline.js"; + +Deno.test("Example.", () => { + example(); +}); -- cgit v1.2.3