mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 07:08:27 -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.
|
// which is only used on linux.
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
#[test]
|
#[test]
|
||||||
fn relative_home_dir() {
|
fn xdg_cache_home_dir() {
|
||||||
use test_util as util;
|
let context = TestContext::with_http_server();
|
||||||
use test_util::TempDir;
|
let deno_dir = context.temp_dir();
|
||||||
|
let xdg_cache_home = deno_dir.path().join("cache");
|
||||||
let deno_dir = TempDir::new();
|
context
|
||||||
let mut deno_cmd = util::deno_cmd();
|
.new_command()
|
||||||
let output = deno_cmd
|
|
||||||
.current_dir(util::testdata_path())
|
|
||||||
.env("XDG_CACHE_HOME", deno_dir.path())
|
|
||||||
.env_remove("HOME")
|
.env_remove("HOME")
|
||||||
.env_remove("DENO_DIR")
|
.env_remove("DENO_DIR")
|
||||||
.arg("cache")
|
.env_clear()
|
||||||
.arg("--reload")
|
.env("XDG_CACHE_HOME", &xdg_cache_home)
|
||||||
.arg("--no-check")
|
.args(
|
||||||
.arg("run/002_hello.ts")
|
"cache --reload --no-check http://localhost:4548/subdir/redirects/a.ts",
|
||||||
.stdout(std::process::Stdio::piped())
|
)
|
||||||
.spawn()
|
.run()
|
||||||
.unwrap()
|
.skip_output_check()
|
||||||
.wait_with_output()
|
.assert_exit_code(0);
|
||||||
.unwrap();
|
assert!(xdg_cache_home.read_dir().count() > 0);
|
||||||
assert!(output.status.success());
|
|
||||||
assert_eq!(output.stdout, b"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
itest!(check_local_by_default {
|
itest!(check_local_by_default {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4481,8 +4481,11 @@ itest!(permission_args_quiet {
|
||||||
// Regression test for https://github.com/denoland/deno/issues/16772
|
// Regression test for https://github.com/denoland/deno/issues/16772
|
||||||
#[test]
|
#[test]
|
||||||
fn file_fetcher_preserves_permissions() {
|
fn file_fetcher_preserves_permissions() {
|
||||||
let _guard = util::http_server();
|
let context = TestContext::with_http_server();
|
||||||
util::with_pty(&["repl", "--quiet"], |mut console| {
|
context
|
||||||
|
.new_command()
|
||||||
|
.args("repl --quiet")
|
||||||
|
.with_pty(|mut console| {
|
||||||
console.write_line(
|
console.write_line(
|
||||||
"const a = await import('http://localhost:4545/run/019_media_types.ts');",
|
"const a = await import('http://localhost:4545/run/019_media_types.ts');",
|
||||||
);
|
);
|
||||||
|
@ -4524,7 +4527,6 @@ fn stdio_streams_are_locked_in_permission_prompt() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn permission_prompt_strips_ansi_codes_and_control_chars() {
|
fn permission_prompt_strips_ansi_codes_and_control_chars() {
|
||||||
let _guard = util::http_server();
|
|
||||||
util::with_pty(&["repl"], |mut console| {
|
util::with_pty(&["repl"], |mut console| {
|
||||||
console.write_line(
|
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" });"#
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -200,6 +201,7 @@ impl TestContext {
|
||||||
args_vec: Default::default(),
|
args_vec: Default::default(),
|
||||||
stdin: Default::default(),
|
stdin: Default::default(),
|
||||||
envs: Default::default(),
|
envs: Default::default(),
|
||||||
|
envs_remove: Default::default(),
|
||||||
env_clear: Default::default(),
|
env_clear: Default::default(),
|
||||||
cwd: Default::default(),
|
cwd: Default::default(),
|
||||||
split_output: false,
|
split_output: false,
|
||||||
|
@ -229,6 +231,7 @@ pub struct TestCommandBuilder {
|
||||||
args_vec: Vec<String>,
|
args_vec: Vec<String>,
|
||||||
stdin: Option<String>,
|
stdin: Option<String>,
|
||||||
envs: HashMap<String, String>,
|
envs: HashMap<String, String>,
|
||||||
|
envs_remove: HashSet<String>,
|
||||||
env_clear: bool,
|
env_clear: bool,
|
||||||
cwd: Option<String>,
|
cwd: Option<String>,
|
||||||
split_output: bool,
|
split_output: bool,
|
||||||
|
@ -280,6 +283,13 @@ impl TestCommandBuilder {
|
||||||
self
|
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>>(
|
pub fn envs<S: AsRef<OsStr>>(
|
||||||
self,
|
self,
|
||||||
envs: impl IntoIterator<Item = (S, S)>,
|
envs: impl IntoIterator<Item = (S, S)>,
|
||||||
|
@ -355,6 +365,13 @@ impl TestCommandBuilder {
|
||||||
|
|
||||||
fn build_envs(&self) -> HashMap<String, String> {
|
fn build_envs(&self) -> HashMap<String, String> {
|
||||||
let mut envs = self.context.envs.clone();
|
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 {
|
for (key, value) in &self.envs {
|
||||||
envs.insert(key.to_string(), value.to_string());
|
envs.insert(key.to_string(), value.to_string());
|
||||||
}
|
}
|
||||||
|
@ -419,7 +436,6 @@ impl TestCommandBuilder {
|
||||||
if self.env_clear {
|
if self.env_clear {
|
||||||
command.env_clear();
|
command.env_clear();
|
||||||
}
|
}
|
||||||
command.env("DENO_DIR", self.context.deno_dir.path());
|
|
||||||
let mut envs = self.build_envs();
|
let mut envs = self.build_envs();
|
||||||
if !envs.contains_key("NPM_CONFIG_REGISTRY") {
|
if !envs.contains_key("NPM_CONFIG_REGISTRY") {
|
||||||
envs.insert("NPM_CONFIG_REGISTRY".to_string(), npm_registry_unset_url());
|
envs.insert("NPM_CONFIG_REGISTRY".to_string(), npm_registry_unset_url());
|
||||||
|
@ -561,8 +577,9 @@ impl TestCommandOutput {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn skip_exit_code_check(&self) {
|
pub fn skip_exit_code_check(&self) -> &Self {
|
||||||
*self.asserted_exit_code.borrow_mut() = true;
|
*self.asserted_exit_code.borrow_mut() = true;
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit_code(&self) -> Option<i32> {
|
pub fn exit_code(&self) -> Option<i32> {
|
||||||
|
|
Loading…
Reference in a new issue