diff options
Diffstat (limited to 'cli/tests')
23 files changed, 347 insertions, 285 deletions
diff --git a/cli/tests/coverage/branch.ts b/cli/tests/coverage/branch.ts new file mode 100644 index 000000000..352167109 --- /dev/null +++ b/cli/tests/coverage/branch.ts @@ -0,0 +1,15 @@ +export function branch(condition: boolean): boolean { + if (condition) { + return true; + } else { + return false; + } +} + +export function unused(condition: boolean): boolean { + if (condition) { + return false; + } else { + return true; + } +} diff --git a/cli/tests/test_branch_coverage.ts b/cli/tests/coverage/branch_test.ts index 7e3adb737..2a44c8071 100644 --- a/cli/tests/test_branch_coverage.ts +++ b/cli/tests/coverage/branch_test.ts @@ -1,4 +1,4 @@ -import { branch } from "./subdir/branch.ts"; +import { branch } from "./branch.ts"; Deno.test("branch", function () { branch(true); diff --git a/cli/tests/coverage/complex.ts b/cli/tests/coverage/complex.ts new file mode 100644 index 000000000..a54c3437b --- /dev/null +++ b/cli/tests/coverage/complex.ts @@ -0,0 +1,68 @@ +// This entire interface should be completely ignored by the coverage tool. +export interface Complex { + // These comments should be ignored. + foo: string; + + // But this is a stub, so this isn't really documentation. + bar: string; + + // Really all these are doing is padding the line count. + baz: string; +} + +// Lets add some wide characters to ensure that the absolute byte offsets are +// being matched properly. +// +// 패딩에 대한 더 많은 문자. +function dependency( + foo: string, + bar: string, + baz: string, +): Complex { + return { + foo, + bar, + baz, + }; +} + +// Again just more wide characters for padding. +// +// 良い対策のためにいくつかのユニコード文字を投げる。 +export function complex( + foo: string, + bar: string, + baz: string, +): Complex { + return dependency( + foo, + bar, + baz, + ); +} + +// And yet again for good measure. +// 更多用於填充的字元。 +export function unused( + foo: string, + bar: string, + baz: string, +): Complex { + return complex( + foo, + bar, + baz, + ); +} + +// Using a non-ascii name again to ensure that the byte offsets match up +// correctly. +export const π = Math.PI; + +// And same applies for this one, this one is unused and will show up in +// lacking coverage. +export function ƒ(): number { + return ( + 0 + ); +} diff --git a/cli/tests/test_complex_coverage.ts b/cli/tests/coverage/complex_test.ts index 06f17d87d..fda948bc3 100644 --- a/cli/tests/test_complex_coverage.ts +++ b/cli/tests/coverage/complex_test.ts @@ -1,4 +1,4 @@ -import { complex } from "./subdir/complex.ts"; +import { complex } from "./complex.ts"; Deno.test("complex", function () { complex("foo", "bar", "baz"); diff --git a/cli/tests/coverage/expected_branch.lcov b/cli/tests/coverage/expected_branch.lcov new file mode 100644 index 000000000..07e29cca5 --- /dev/null +++ b/cli/tests/coverage/expected_branch.lcov @@ -0,0 +1,27 @@ +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/coverage/expected_branch.out b/cli/tests/coverage/expected_branch.out new file mode 100644 index 000000000..630ea93b2 --- /dev/null +++ b/cli/tests/coverage/expected_branch.out @@ -0,0 +1,12 @@ +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/coverage/expected_complex.lcov b/cli/tests/coverage/expected_complex.lcov new file mode 100644 index 000000000..0182b3de7 --- /dev/null +++ b/cli/tests/coverage/expected_complex.lcov @@ -0,0 +1,52 @@ +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 +LH:22 +LF:36 +end_of_record diff --git a/cli/tests/coverage/expected_complex.out b/cli/tests/coverage/expected_complex.out new file mode 100644 index 000000000..1dee78a87 --- /dev/null +++ b/cli/tests/coverage/expected_complex.out @@ -0,0 +1,17 @@ +cover [WILDCARD]/coverage/complex.ts ... 61.111% (22/36) + 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 | ); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index e57bca27f..f9f458016 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -3612,48 +3612,6 @@ console.log("finish"); output: "redirect_cache.out", }); - itest!(deno_test_coverage { - args: "test --coverage --unstable test_coverage.ts", - output: "test_coverage.out", - exit_code: 0, - }); - - itest!(deno_test_comment_coverage { - args: "test --coverage --unstable test_comment_coverage.ts", - output: "test_comment_coverage.out", - exit_code: 0, - }); - - itest!(deno_test_branch_coverage { - args: "test --coverage --unstable test_branch_coverage.ts", - output: "test_branch_coverage.out", - exit_code: 0, - }); - - itest!(deno_test_coverage_explicit { - args: "test --coverage=.test_coverage --unstable test_coverage.ts", - output: "test_coverage.out", - exit_code: 0, - }); - - itest!(deno_test_run_test_coverage { - args: "test --allow-all --coverage --unstable test_run_test_coverage.ts", - output: "test_run_test_coverage.out", - exit_code: 0, - }); - - itest!(deno_test_run_run_coverage { - args: "test --allow-all --coverage --unstable test_run_run_coverage.ts", - output: "test_run_run_coverage.out", - exit_code: 0, - }); - - itest!(deno_test_run_combined_coverage { - args: "test --allow-all --coverage --unstable test_run_run_coverage.ts test_run_test_coverage.ts", - output: "test_run_combined_coverage.out", - exit_code: 0, - }); - itest!(deno_lint { args: "lint --unstable lint/file1.js lint/file2.ts lint/ignored_file.ts", output: "lint/expected.out", @@ -3988,6 +3946,160 @@ console.log("finish"); assert_eq!(output.stderr, b""); } + mod coverage { + use super::*; + + #[test] + fn branch() { + let tempdir = TempDir::new().expect("tempdir fail"); + let status = util::deno_cmd() + .current_dir(util::root_path()) + .arg("test") + .arg("--quiet") + .arg("--unstable") + .arg(format!("--coverage={}", tempdir.path().to_str().unwrap())) + .arg("cli/tests/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::root_path()) + .arg("coverage") + .arg("--quiet") + .arg("--unstable") + .arg(format!("{}/", tempdir.path().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::root_path().join("cli/tests/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::root_path()) + .arg("coverage") + .arg("--quiet") + .arg("--unstable") + .arg("--lcov") + .arg(format!("{}/", tempdir.path().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::root_path().join("cli/tests/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()); + } + + #[test] + fn complex() { + let tempdir = TempDir::new().expect("tempdir fail"); + let status = util::deno_cmd() + .current_dir(util::root_path()) + .arg("test") + .arg("--quiet") + .arg("--unstable") + .arg(format!("--coverage={}", tempdir.path().to_str().unwrap())) + .arg("cli/tests/coverage/complex_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::root_path()) + .arg("coverage") + .arg("--quiet") + .arg("--unstable") + .arg(format!("{}/", tempdir.path().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::root_path().join("cli/tests/coverage/expected_complex.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::root_path()) + .arg("coverage") + .arg("--quiet") + .arg("--unstable") + .arg("--lcov") + .arg(format!("{}/", tempdir.path().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::root_path().join("cli/tests/coverage/expected_complex.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()); + } + } + mod permissions { use super::*; diff --git a/cli/tests/run_coverage.ts b/cli/tests/run_coverage.ts deleted file mode 100644 index d1443dfad..000000000 --- a/cli/tests/run_coverage.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { returnsHi } from "./subdir/mod1.ts"; - -returnsHi(); diff --git a/cli/tests/subdir/branch.ts b/cli/tests/subdir/branch.ts deleted file mode 100644 index bb7aec9eb..000000000 --- a/cli/tests/subdir/branch.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function branch(condition: boolean): boolean { - if (condition) { - return true; - } else { - return false; - } -} diff --git a/cli/tests/subdir/complex.ts b/cli/tests/subdir/complex.ts deleted file mode 100644 index 588e6ce59..000000000 --- a/cli/tests/subdir/complex.ts +++ /dev/null @@ -1,35 +0,0 @@ -// This entire interface should be completely ignored by the coverage tool. -export interface Complex { - // These are comments. - foo: string; - - // But this is a stub, so this isn't really documentation. - bar: string; - - // Really all these are doing is padding the line count. - baz: string; -} - -export function complex( - foo: string, - bar: string, - baz: string, -): Complex { - return { - foo, - bar, - baz, - }; -} - -export function unused( - foo: string, - bar: string, - baz: string, -): Complex { - return complex( - foo, - bar, - baz, - ); -} diff --git a/cli/tests/test_branch_coverage.out b/cli/tests/test_branch_coverage.out deleted file mode 100644 index 375073e36..000000000 --- a/cli/tests/test_branch_coverage.out +++ /dev/null @@ -1,10 +0,0 @@ -Check [WILDCARD]/tests/$deno$test.ts -running 1 tests -test branch ... ok ([WILDCARD]) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -cover [WILDCARD]/tests/subdir/branch.ts ... 57.143% (4/7) - 4 | } else { - 5 | return false; - 6 | } diff --git a/cli/tests/test_comment_coverage.out b/cli/tests/test_comment_coverage.out deleted file mode 100644 index ce846836c..000000000 --- a/cli/tests/test_comment_coverage.out +++ /dev/null @@ -1,7 +0,0 @@ -[WILDCARD]/tests/$deno$test.ts -running 1 tests -test comment ... ok ([WILDCARD]) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -[WILDCARD]/tests/subdir/comment.ts ... 100.000% (3/3) diff --git a/cli/tests/test_comment_coverage.ts b/cli/tests/test_comment_coverage.ts deleted file mode 100644 index 28a25c65d..000000000 --- a/cli/tests/test_comment_coverage.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { comment } from "./subdir/comment.ts"; - -Deno.test("comment", function () { - comment(); -}); diff --git a/cli/tests/test_complex_coverage.out b/cli/tests/test_complex_coverage.out deleted file mode 100644 index 1082d098c..000000000 --- a/cli/tests/test_complex_coverage.out +++ /dev/null @@ -1,18 +0,0 @@ -Check [WILDCARD]/tests/$deno$test.ts -running 1 tests -test complex ... ok ([WILDCARD]) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -cover [WILDCARD]/tests/subdir/complex.ts ... 50.000% (10/20) - 25 | export function unused( - 26 | foo: string, - 27 | bar: string, - 28 | baz: string, ------|----- - 30 | return complex( - 31 | foo, - 32 | bar, - 33 | baz, - 34 | ); - 35 | } diff --git a/cli/tests/test_coverage.out b/cli/tests/test_coverage.out deleted file mode 100644 index 83456bced..000000000 --- a/cli/tests/test_coverage.out +++ /dev/null @@ -1,26 +0,0 @@ -Check [WILDCARD]/$deno$test.ts -running 1 tests -test returnsFooSuccess ... ok ([WILDCARD]) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -cover [WILDCARD]/tests/subdir/mod1.ts ... 30.769% (4/13) - 3 | export function returnsHi(): string { - 4 | return "Hi"; - 5 | } ------|----- - 11 | export function printHello3(): void { - 12 | printHello2(); - 13 | } ------|----- - 15 | export function throwsError(): void { - 16 | throw Error("exception from mod1"); - 17 | } -cover [WILDCARD]/tests/subdir/print_hello.ts ... 0.000% (0/3) - 1 | export function printHello(): void { - 2 | console.log("Hello"); - 3 | } -cover [WILDCARD]/tests/subdir/subdir2/mod2.ts ... 57.143% (4/7) - 7 | export function printHello2(): void { - 8 | printHello(); - 9 | } diff --git a/cli/tests/test_coverage.ts b/cli/tests/test_coverage.ts deleted file mode 100644 index 0c576d612..000000000 --- a/cli/tests/test_coverage.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { returnsFoo2 } from "./subdir/mod1.ts"; - -Deno.test("returnsFooSuccess", function () { - returnsFoo2(); -}); diff --git a/cli/tests/test_run_combined_coverage.out b/cli/tests/test_run_combined_coverage.out deleted file mode 100644 index 9a638214e..000000000 --- a/cli/tests/test_run_combined_coverage.out +++ /dev/null @@ -1,32 +0,0 @@ -Check [WILDCARD]/tests/$deno$test.ts -running 2 tests -test spawn test ... Check [WILDCARD]/tests/run_coverage.ts -ok ([WILDCARD]) -test spawn test ... Check [WILDCARD]/tests/$deno$test.ts -running 1 tests -test returnsFooSuccess ... ok ([WILDCARD]) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -ok ([WILDCARD]) - -test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -cover [WILDCARD]/tests/run_coverage.ts ... 100.000% (2/2) -cover [WILDCARD]/tests/subdir/mod1.ts ... 53.846% (7/13) - 11 | export function printHello3(): void { - 12 | printHello2(); - 13 | } ------|----- - 15 | export function throwsError(): void { - 16 | throw Error("exception from mod1"); - 17 | } -cover [WILDCARD]/tests/subdir/print_hello.ts ... 0.000% (0/3) - 1 | export function printHello(): void { - 2 | console.log("Hello"); - 3 | } -cover [WILDCARD]/tests/subdir/subdir2/mod2.ts ... 57.143% (4/7) - 7 | export function printHello2(): void { - 8 | printHello(); - 9 | } -cover [WILDCARD]/tests/test_coverage.ts ... 100.000% (4/4) diff --git a/cli/tests/test_run_run_coverage.out b/cli/tests/test_run_run_coverage.out deleted file mode 100644 index 81f86c9be..000000000 --- a/cli/tests/test_run_run_coverage.out +++ /dev/null @@ -1,32 +0,0 @@ -Check [WILDCARD]/tests/$deno$test.ts -running 1 tests -test spawn test ... Check [WILDCARD]/tests/run_coverage.ts -ok ([WILDCARD]) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -cover [WILDCARD]/tests/run_coverage.ts ... 100.000% (2/2) -cover [WILDCARD]/tests/subdir/mod1.ts ... 30.769% (4/13) - 7 | export function returnsFoo2(): string { - 8 | return returnsFoo(); - 9 | } ------|----- - 11 | export function printHello3(): void { - 12 | printHello2(); - 13 | } ------|----- - 15 | export function throwsError(): void { - 16 | throw Error("exception from mod1"); - 17 | } -cover [WILDCARD]/tests/subdir/print_hello.ts ... 0.000% (0/3) - 1 | export function printHello(): void { - 2 | console.log("Hello"); - 3 | } -cover [WILDCARD]/tests/subdir/subdir2/mod2.ts ... 14.286% (1/7) - 3 | export function returnsFoo(): string { - 4 | return "Foo"; - 5 | } ------|----- - 7 | export function printHello2(): void { - 8 | printHello(); - 9 | } diff --git a/cli/tests/test_run_run_coverage.ts b/cli/tests/test_run_run_coverage.ts deleted file mode 100644 index 448b15e7b..000000000 --- a/cli/tests/test_run_run_coverage.ts +++ /dev/null @@ -1,14 +0,0 @@ -Deno.test("spawn test", async function () { - const process = Deno.run({ - cmd: [ - Deno.execPath(), - "run", - "--allow-all", - "--unstable", - "run_coverage.ts", - ], - }); - - await process.status(); - process.close(); -}); diff --git a/cli/tests/test_run_test_coverage.out b/cli/tests/test_run_test_coverage.out deleted file mode 100644 index aa524966e..000000000 --- a/cli/tests/test_run_test_coverage.out +++ /dev/null @@ -1,33 +0,0 @@ -Check [WILDCARD]/tests/$deno$test.ts -running 1 tests -test spawn test ... Check [WILDCARD]/tests/$deno$test.ts -running 1 tests -test returnsFooSuccess ... ok ([WILDCARD]) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -ok ([WILDCARD]) - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) - -cover [WILDCARD]/tests/subdir/mod1.ts ... 30.769% (4/13) - 3 | export function returnsHi(): string { - 4 | return "Hi"; - 5 | } ------|----- - 11 | export function printHello3(): void { - 12 | printHello2(); - 13 | } ------|----- - 15 | export function throwsError(): void { - 16 | throw Error("exception from mod1"); - 17 | } -cover [WILDCARD]/tests/subdir/print_hello.ts ... 0.000% (0/3) - 1 | export function printHello(): void { - 2 | console.log("Hello"); - 3 | } -cover [WILDCARD]/tests/subdir/subdir2/mod2.ts ... 57.143% (4/7) - 7 | export function printHello2(): void { - 8 | printHello(); - 9 | } -cover [WILDCARD]/tests/test_coverage.ts ... 100.000% (4/4) diff --git a/cli/tests/test_run_test_coverage.ts b/cli/tests/test_run_test_coverage.ts deleted file mode 100644 index e3f0e47ce..000000000 --- a/cli/tests/test_run_test_coverage.ts +++ /dev/null @@ -1,14 +0,0 @@ -Deno.test("spawn test", async function () { - const process = Deno.run({ - cmd: [ - Deno.execPath(), - "test", - "--allow-all", - "--unstable", - "test_coverage.ts", - ], - }); - - await process.status(); - process.close(); -}); |