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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
.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());
|
|
|
|
}
|