mirror of
https://github.com/denoland/deno.git
synced 2025-01-05 13:59:01 -05:00
chore: switch compile tests over to the TestBuilder (#21180)
This commit is contained in:
parent
1a2d8cfc98
commit
3f17633de9
4 changed files with 509 additions and 565 deletions
|
@ -57,28 +57,23 @@ itest!(ignore_require {
|
|||
// which is only used on linux.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn relative_home_dir() {
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
let deno_dir = TempDir::new();
|
||||
let mut deno_cmd = util::deno_cmd();
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.env("XDG_CACHE_HOME", deno_dir.path())
|
||||
fn xdg_cache_home_dir() {
|
||||
let context = TestContext::with_http_server();
|
||||
let deno_dir = context.temp_dir();
|
||||
let xdg_cache_home = deno_dir.path().join("cache");
|
||||
context
|
||||
.new_command()
|
||||
.env_remove("HOME")
|
||||
.env_remove("DENO_DIR")
|
||||
.arg("cache")
|
||||
.arg("--reload")
|
||||
.arg("--no-check")
|
||||
.arg("run/002_hello.ts")
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"");
|
||||
.env_clear()
|
||||
.env("XDG_CACHE_HOME", &xdg_cache_home)
|
||||
.args(
|
||||
"cache --reload --no-check http://localhost:4548/subdir/redirects/a.ts",
|
||||
)
|
||||
.run()
|
||||
.skip_output_check()
|
||||
.assert_exit_code(0);
|
||||
assert!(xdg_cache_home.read_dir().count() > 0);
|
||||
}
|
||||
|
||||
itest!(check_local_by_default {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4481,15 +4481,18 @@ itest!(permission_args_quiet {
|
|||
// Regression test for https://github.com/denoland/deno/issues/16772
|
||||
#[test]
|
||||
fn file_fetcher_preserves_permissions() {
|
||||
let _guard = util::http_server();
|
||||
util::with_pty(&["repl", "--quiet"], |mut console| {
|
||||
console.write_line(
|
||||
let context = TestContext::with_http_server();
|
||||
context
|
||||
.new_command()
|
||||
.args("repl --quiet")
|
||||
.with_pty(|mut console| {
|
||||
console.write_line(
|
||||
"const a = await import('http://localhost:4545/run/019_media_types.ts');",
|
||||
);
|
||||
console.expect("Allow?");
|
||||
console.write_line_raw("y");
|
||||
console.expect_all(&["success", "true"]);
|
||||
});
|
||||
console.expect("Allow?");
|
||||
console.write_line_raw("y");
|
||||
console.expect_all(&["success", "true"]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -4524,11 +4527,10 @@ fn stdio_streams_are_locked_in_permission_prompt() {
|
|||
|
||||
#[test]
|
||||
fn permission_prompt_strips_ansi_codes_and_control_chars() {
|
||||
let _guard = util::http_server();
|
||||
util::with_pty(&["repl"], |mut console| {
|
||||
console.write_line(
|
||||
r#"Deno.permissions.request({ name: "env", variable: "\rDo you like ice cream? y/n" });"#
|
||||
);
|
||||
r#"Deno.permissions.request({ name: "env", variable: "\rDo you like ice cream? y/n" });"#
|
||||
);
|
||||
// will be uppercase on windows
|
||||
let env_name = if cfg!(windows) {
|
||||
"DO YOU LIKE ICE CREAM? Y/N"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::ffi::OsStr;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
@ -200,6 +201,7 @@ impl TestContext {
|
|||
args_vec: Default::default(),
|
||||
stdin: Default::default(),
|
||||
envs: Default::default(),
|
||||
envs_remove: Default::default(),
|
||||
env_clear: Default::default(),
|
||||
cwd: Default::default(),
|
||||
split_output: false,
|
||||
|
@ -229,6 +231,7 @@ pub struct TestCommandBuilder {
|
|||
args_vec: Vec<String>,
|
||||
stdin: Option<String>,
|
||||
envs: HashMap<String, String>,
|
||||
envs_remove: HashSet<String>,
|
||||
env_clear: bool,
|
||||
cwd: Option<String>,
|
||||
split_output: bool,
|
||||
|
@ -280,6 +283,13 @@ impl TestCommandBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn env_remove(mut self, key: impl AsRef<OsStr>) -> Self {
|
||||
self
|
||||
.envs_remove
|
||||
.insert(key.as_ref().to_string_lossy().to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn envs<S: AsRef<OsStr>>(
|
||||
self,
|
||||
envs: impl IntoIterator<Item = (S, S)>,
|
||||
|
@ -355,6 +365,13 @@ impl TestCommandBuilder {
|
|||
|
||||
fn build_envs(&self) -> HashMap<String, String> {
|
||||
let mut envs = self.context.envs.clone();
|
||||
envs.insert(
|
||||
"DENO_DIR".to_string(),
|
||||
self.context.deno_dir.path().to_string(),
|
||||
);
|
||||
for key in &self.envs_remove {
|
||||
envs.remove(key);
|
||||
}
|
||||
for (key, value) in &self.envs {
|
||||
envs.insert(key.to_string(), value.to_string());
|
||||
}
|
||||
|
@ -419,7 +436,6 @@ impl TestCommandBuilder {
|
|||
if self.env_clear {
|
||||
command.env_clear();
|
||||
}
|
||||
command.env("DENO_DIR", self.context.deno_dir.path());
|
||||
let mut envs = self.build_envs();
|
||||
if !envs.contains_key("NPM_CONFIG_REGISTRY") {
|
||||
envs.insert("NPM_CONFIG_REGISTRY".to_string(), npm_registry_unset_url());
|
||||
|
@ -561,8 +577,9 @@ impl TestCommandOutput {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn skip_exit_code_check(&self) {
|
||||
pub fn skip_exit_code_check(&self) -> &Self {
|
||||
*self.asserted_exit_code.borrow_mut() = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn exit_code(&self) -> Option<i32> {
|
||||
|
|
Loading…
Reference in a new issue