diff options
Diffstat (limited to 'cli/tests/integration/check_tests.rs')
-rw-r--r-- | cli/tests/integration/check_tests.rs | 147 |
1 files changed, 80 insertions, 67 deletions
diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index d1148b244..7f9ff3ff5 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -1,11 +1,10 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use std::process::Command; -use std::process::Stdio; use test_util as util; use util::env_vars_for_npm_tests; use util::env_vars_for_npm_tests_no_sync_download; -use util::TempDir; +use util::TestContext; itest!(_095_check_with_bare_import { args: "check cache/095_cache_with_bare_import.ts", @@ -87,31 +86,34 @@ itest!(check_no_error_truncation { #[test] fn cache_switching_config_then_no_config() { - let deno_dir = util::new_deno_dir(); - assert!(does_type_checking(&deno_dir, true)); - assert!(does_type_checking(&deno_dir, false)); + let context = TestContext::default(); + + assert!(does_type_checking(&context, true)); + assert!(does_type_checking(&context, false)); // should now not do type checking even when it changes // configs because it previously did - assert!(!does_type_checking(&deno_dir, true)); - assert!(!does_type_checking(&deno_dir, false)); - - fn does_type_checking(deno_dir: &util::TempDir, with_config: bool) -> bool { - let mut cmd = util::deno_cmd_with_deno_dir(deno_dir); - cmd - .current_dir(util::testdata_path()) - .stderr(Stdio::piped()) - .arg("check") - .arg("check/cache_config_on_off/main.ts"); + assert!(!does_type_checking(&context, true)); + assert!(!does_type_checking(&context, false)); + + fn does_type_checking(context: &TestContext, with_config: bool) -> bool { + let mut args = vec![ + "check".to_string(), + "check/cache_config_on_off/main.ts".to_string(), + ]; if with_config { - cmd - .arg("--config") - .arg("check/cache_config_on_off/deno.json"); + let mut slice = vec![ + "--config".to_string(), + "check/cache_config_on_off/deno.json".to_string(), + ]; + args.append(&mut slice); } - let output = cmd.spawn().unwrap().wait_with_output().unwrap(); - assert!(output.status.success()); - let stderr = std::str::from_utf8(&output.stderr).unwrap(); + let output = context.new_command().args_vec(args).split_output().run(); + + output.assert_exit_code(0); + + let stderr = output.stderr(); stderr.contains("Check") } } @@ -119,61 +121,72 @@ fn cache_switching_config_then_no_config() { #[test] fn reload_flag() { // should do type checking whenever someone specifies --reload - let deno_dir = util::new_deno_dir(); - assert!(does_type_checking(&deno_dir, false)); - assert!(!does_type_checking(&deno_dir, false)); - assert!(does_type_checking(&deno_dir, true)); - assert!(does_type_checking(&deno_dir, true)); - assert!(!does_type_checking(&deno_dir, false)); - - fn does_type_checking(deno_dir: &util::TempDir, reload: bool) -> bool { - let mut cmd = util::deno_cmd_with_deno_dir(deno_dir); - cmd - .current_dir(util::testdata_path()) - .stderr(Stdio::piped()) - .arg("check") - .arg("check/cache_config_on_off/main.ts"); + let context = TestContext::default(); + + assert!(does_type_checking(&context, false)); + assert!(!does_type_checking(&context, false)); + assert!(does_type_checking(&context, true)); + assert!(does_type_checking(&context, true)); + assert!(!does_type_checking(&context, false)); + + fn does_type_checking(context: &TestContext, reload: bool) -> bool { + let mut args = vec![ + "check".to_string(), + "check/cache_config_on_off/main.ts".to_string(), + ]; if reload { - cmd.arg("--reload"); + let mut slice = vec!["--reload".to_string()]; + args.append(&mut slice); } - let output = cmd.spawn().unwrap().wait_with_output().unwrap(); - assert!(output.status.success()); + let output = context.new_command().args_vec(args).split_output().run(); + output.assert_exit_code(0); - let stderr = std::str::from_utf8(&output.stderr).unwrap(); + let stderr = output.stderr(); stderr.contains("Check") } } #[test] fn typecheck_declarations_ns() { - let output = util::deno_cmd() - .arg("test") - .arg("--doc") - .arg(util::root_path().join("cli/tsc/dts/lib.deno.ns.d.ts")) - .output() - .unwrap(); - println!("stdout: {}", String::from_utf8(output.stdout).unwrap()); - println!("stderr: {}", String::from_utf8(output.stderr).unwrap()); - assert!(output.status.success()); + let context = TestContext::default(); + let args = vec![ + "test".to_string(), + "--doc".to_string(), + util::root_path() + .join("cli/tsc/dts/lib.deno.ns.d.ts") + .to_string_lossy() + .into_owned(), + ]; + let output = context.new_command().args_vec(args).split_output().run(); + + println!("stdout: {}", output.stdout()); + println!("stderr: {}", output.stderr()); + output.assert_exit_code(0); } #[test] fn typecheck_declarations_unstable() { - let output = util::deno_cmd() - .arg("test") - .arg("--doc") - .arg("--unstable") - .arg(util::root_path().join("cli/tsc/dts/lib.deno.unstable.d.ts")) - .output() - .unwrap(); - println!("stdout: {}", String::from_utf8(output.stdout).unwrap()); - println!("stderr: {}", String::from_utf8(output.stderr).unwrap()); - assert!(output.status.success()); + let context = TestContext::default(); + let args = vec![ + "test".to_string(), + "--doc".to_string(), + "--unstable".to_string(), + util::root_path() + .join("cli/tsc/dts/lib.deno.unstable.d.ts") + .to_string_lossy() + .into_owned(), + ]; + let output = context.new_command().args_vec(args).split_output().run(); + + println!("stdout: {}", output.stdout()); + println!("stderr: {}", output.stderr()); + output.assert_exit_code(0); } #[test] fn typecheck_core() { - let deno_dir = TempDir::new(); + let context = TestContext::default(); + let deno_dir = context.deno_dir(); let test_file = deno_dir.path().join("test_deno_core_types.ts"); std::fs::write( &test_file, @@ -189,18 +202,18 @@ fn typecheck_core() { ), ) .unwrap(); - let output = util::deno_cmd_with_deno_dir(&deno_dir) - .arg("run") - .arg(test_file.to_str().unwrap()) - .output() - .unwrap(); - println!("stdout: {}", String::from_utf8(output.stdout).unwrap()); - println!("stderr: {}", String::from_utf8(output.stderr).unwrap()); - assert!(output.status.success()); + + let args = vec!["run".to_string(), test_file.to_string_lossy().into_owned()]; + let output = context.new_command().args_vec(args).split_output().run(); + + println!("stdout: {}", output.stdout()); + println!("stderr: {}", output.stderr()); + output.assert_exit_code(0); } #[test] fn ts_no_recheck_on_redirect() { + // TODO: port to test builder let deno_dir = util::new_deno_dir(); let e = util::deno_exe_path(); |