2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
use std::fs;
|
|
|
|
use test_util as util;
|
2022-04-01 11:15:37 -04:00
|
|
|
use test_util::TempDir;
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn branch() {
|
2021-12-23 20:02:54 -05:00
|
|
|
run_coverage_text("branch", "ts");
|
2021-06-27 13:27:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn complex() {
|
2021-12-23 20:02:54 -05:00
|
|
|
run_coverage_text("complex", "ts");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn final_blankline() {
|
|
|
|
run_coverage_text("final_blankline", "js");
|
|
|
|
}
|
|
|
|
|
2022-05-04 07:10:55 -04:00
|
|
|
#[test]
|
|
|
|
fn no_snaps() {
|
|
|
|
no_snaps_included("no_snaps_included", "ts");
|
|
|
|
}
|
|
|
|
|
2021-12-23 20:02:54 -05:00
|
|
|
fn run_coverage_text(test_name: &str, extension: &str) {
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
|
|
|
let tempdir = TempDir::new();
|
2021-12-23 20:02:54 -05:00
|
|
|
let tempdir = tempdir.path().join("cov");
|
2022-01-10 11:36:58 -05:00
|
|
|
|
2022-04-01 11:15:37 -04:00
|
|
|
let status = util::deno_cmd_with_deno_dir(&deno_dir)
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("test")
|
2022-08-12 15:21:17 -04:00
|
|
|
.arg("-A")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("--quiet")
|
|
|
|
.arg("--unstable")
|
2021-12-23 20:02:54 -05:00
|
|
|
.arg(format!("--coverage={}", tempdir.to_str().unwrap()))
|
|
|
|
.arg(format!("coverage/{}_test.{}", test_name, extension))
|
2021-06-27 13:27:36 -04:00
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::inherit())
|
|
|
|
.status()
|
2022-03-22 15:10:00 -04:00
|
|
|
.unwrap();
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
assert!(status.success());
|
|
|
|
|
2022-04-01 11:15:37 -04:00
|
|
|
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("coverage")
|
|
|
|
.arg("--unstable")
|
2021-12-23 20:02:54 -05:00
|
|
|
.arg(format!("{}/", tempdir.to_str().unwrap()))
|
2021-06-27 13:27:36 -04:00
|
|
|
.stdout(std::process::Stdio::piped())
|
2022-01-10 11:36:58 -05:00
|
|
|
.stderr(std::process::Stdio::piped())
|
2021-06-27 13:27:36 -04:00
|
|
|
.output()
|
2022-03-22 15:10:00 -04:00
|
|
|
.unwrap();
|
2021-06-27 13:27:36 -04:00
|
|
|
|
2022-01-10 11:36:58 -05:00
|
|
|
// Verify there's no "Check" being printed
|
|
|
|
assert!(output.stderr.is_empty());
|
|
|
|
|
2021-06-27 13:27:36 -04:00
|
|
|
let actual =
|
|
|
|
util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap())
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let expected = fs::read_to_string(
|
2021-12-23 20:02:54 -05:00
|
|
|
util::testdata_path().join(format!("coverage/{}_expected.out", test_name)),
|
2021-06-27 13:27:36 -04:00
|
|
|
)
|
|
|
|
.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());
|
|
|
|
|
2022-04-01 11:15:37 -04:00
|
|
|
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("coverage")
|
|
|
|
.arg("--quiet")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--lcov")
|
2021-12-23 20:02:54 -05:00
|
|
|
.arg(format!("{}/", tempdir.to_str().unwrap()))
|
2021-06-27 13:27:36 -04:00
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::inherit())
|
|
|
|
.output()
|
2022-03-22 15:10:00 -04:00
|
|
|
.unwrap();
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
let actual =
|
|
|
|
util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap())
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
let expected = fs::read_to_string(
|
2021-12-23 20:02:54 -05:00
|
|
|
util::testdata_path().join(format!("coverage/{}_expected.lcov", test_name)),
|
2021-06-27 13:27:36 -04:00
|
|
|
)
|
|
|
|
.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());
|
|
|
|
}
|
2022-01-11 15:17:25 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multifile_coverage() {
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
|
|
|
let tempdir = TempDir::new();
|
2022-01-11 15:17:25 -05:00
|
|
|
let tempdir = tempdir.path().join("cov");
|
|
|
|
|
2022-04-01 11:15:37 -04:00
|
|
|
let status = util::deno_cmd_with_deno_dir(&deno_dir)
|
2022-01-11 15:17:25 -05:00
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("test")
|
|
|
|
.arg("--quiet")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg(format!("--coverage={}", tempdir.to_str().unwrap()))
|
|
|
|
.arg("coverage/multifile/")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::inherit())
|
|
|
|
.status()
|
2022-03-22 15:10:00 -04:00
|
|
|
.unwrap();
|
2022-01-11 15:17:25 -05:00
|
|
|
|
|
|
|
assert!(status.success());
|
|
|
|
|
2022-04-01 11:15:37 -04:00
|
|
|
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
2022-01-11 15:17:25 -05:00
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("coverage")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg(format!("{}/", tempdir.to_str().unwrap()))
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.output()
|
2022-03-22 15:10:00 -04:00
|
|
|
.unwrap();
|
2022-01-11 15:17:25 -05:00
|
|
|
|
|
|
|
// Verify there's no "Check" being printed
|
|
|
|
assert!(output.stderr.is_empty());
|
|
|
|
|
|
|
|
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/multifile/expected.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());
|
|
|
|
|
2022-04-01 11:15:37 -04:00
|
|
|
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
2022-01-11 15:17:25 -05:00
|
|
|
.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()
|
2022-03-22 15:10:00 -04:00
|
|
|
.unwrap();
|
2022-01-11 15:17:25 -05:00
|
|
|
|
|
|
|
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/multifile/expected.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());
|
|
|
|
}
|
2022-05-04 07:10:55 -04:00
|
|
|
|
|
|
|
fn no_snaps_included(test_name: &str, extension: &str) {
|
|
|
|
let deno_dir = TempDir::new();
|
|
|
|
let tempdir = TempDir::new();
|
|
|
|
let tempdir = tempdir.path().join("cov");
|
|
|
|
|
|
|
|
let status = util::deno_cmd_with_deno_dir(&deno_dir)
|
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("test")
|
|
|
|
.arg("--quiet")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--allow-read")
|
|
|
|
.arg(format!("--coverage={}", tempdir.to_str().unwrap()))
|
|
|
|
.arg(format!(
|
|
|
|
"coverage/no_snaps_included/{}_test.{}",
|
|
|
|
test_name, extension
|
|
|
|
))
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.status()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(status.success());
|
|
|
|
|
|
|
|
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("coverage")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg(format!("{}/", tempdir.to_str().unwrap()))
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// Verify there's no "Check" being printed
|
|
|
|
assert!(output.stderr.is_empty());
|
|
|
|
|
|
|
|
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/no_snaps_included/expected.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());
|
|
|
|
}
|
2022-05-22 10:45:22 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_transpiled_lines() {
|
|
|
|
let deno_dir = TempDir::new();
|
|
|
|
let tempdir = TempDir::new();
|
|
|
|
let tempdir = tempdir.path().join("cov");
|
|
|
|
|
|
|
|
let status = util::deno_cmd_with_deno_dir(&deno_dir)
|
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("test")
|
|
|
|
.arg("--quiet")
|
|
|
|
.arg(format!("--coverage={}", tempdir.to_str().unwrap()))
|
|
|
|
.arg("coverage/no_transpiled_lines/")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::inherit())
|
|
|
|
.status()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(status.success());
|
|
|
|
|
|
|
|
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("coverage")
|
|
|
|
.arg(format!("{}/", tempdir.to_str().unwrap()))
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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/no_transpiled_lines/expected.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_with_deno_dir(&deno_dir)
|
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("coverage")
|
|
|
|
.arg("--lcov")
|
|
|
|
.arg(format!("{}/", tempdir.to_str().unwrap()))
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::inherit())
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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/no_transpiled_lines/expected.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());
|
|
|
|
}
|