summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/integration/bench_tests.rs39
-rw-r--r--cli/tests/integration/cert_tests.rs173
-rw-r--r--cli/tests/integration/lint_tests.rs26
-rw-r--r--cli/tests/integration/mod.rs61
-rw-r--r--cli/tests/integration/test_tests.rs12
5 files changed, 166 insertions, 145 deletions
diff --git a/cli/tests/integration/bench_tests.rs b/cli/tests/integration/bench_tests.rs
index 240c4b2d4..4e94463e5 100644
--- a/cli/tests/integration/bench_tests.rs
+++ b/cli/tests/integration/bench_tests.rs
@@ -2,7 +2,11 @@
use deno_core::url::Url;
use test_util as util;
+use util::assert_contains;
+use util::assert_exit_code;
+use util::assert_output_file;
use util::env_vars_for_npm_tests;
+use util::TestContext;
itest!(overloads {
args: "bench bench/overloads.ts",
@@ -187,19 +191,16 @@ itest!(json_output {
#[test]
fn recursive_permissions_pledge() {
- let output = util::deno_cmd()
- .current_dir(util::testdata_path())
- .arg("bench")
- .arg("bench/recursive_permissions_pledge.js")
- .stderr(std::process::Stdio::piped())
- .spawn()
- .unwrap()
- .wait_with_output()
- .unwrap();
- assert!(!output.status.success());
- assert!(String::from_utf8(output.stderr).unwrap().contains(
+ let context = TestContext::default();
+ let output = context
+ .new_command()
+ .args("bench bench/recursive_permissions_pledge.js")
+ .run();
+ assert_exit_code!(output, 1);
+ assert_contains!(
+ output.text(),
"pledge test permissions called before restoring previous pledge"
- ));
+ );
}
#[test]
@@ -208,14 +209,12 @@ fn file_protocol() {
Url::from_file_path(util::testdata_path().join("bench/file_protocol.ts"))
.unwrap()
.to_string();
-
- (util::CheckOutputIntegrationTest {
- args_vec: vec!["bench", &file_url],
- exit_code: 0,
- output: "bench/file_protocol.out",
- ..Default::default()
- })
- .run();
+ let context = TestContext::default();
+ let output = context
+ .new_command()
+ .args(format!("bench bench/file_protocol.ts {file_url}"))
+ .run();
+ assert_output_file!(output, "bench/file_protocol.out");
}
itest!(package_json_basic {
diff --git a/cli/tests/integration/cert_tests.rs b/cli/tests/integration/cert_tests.rs
index 320e1b2a9..8fa439d78 100644
--- a/cli/tests/integration/cert_tests.rs
+++ b/cli/tests/integration/cert_tests.rs
@@ -3,6 +3,7 @@
use deno_runtime::deno_net::ops_tls::TlsStream;
use deno_runtime::deno_tls::rustls;
use deno_runtime::deno_tls::rustls_pemfile;
+use lsp_types::Url;
use std::io::BufReader;
use std::io::Cursor;
use std::io::Read;
@@ -11,6 +12,9 @@ use std::sync::Arc;
use test_util as util;
use test_util::TempDir;
use tokio::task::LocalSet;
+use util::assert_exit_code;
+use util::assert_output_text;
+use util::TestContext;
itest_flaky!(cafile_url_imports {
args: "run --quiet --reload --cert tls/RootCA.pem cert/cafile_url_imports.ts",
@@ -19,132 +23,113 @@ itest_flaky!(cafile_url_imports {
});
itest_flaky!(cafile_ts_fetch {
- args:
- "run --quiet --reload --allow-net --cert tls/RootCA.pem cert/cafile_ts_fetch.ts",
- output: "cert/cafile_ts_fetch.ts.out",
- http_server: true,
- });
+ args:
+ "run --quiet --reload --allow-net --cert tls/RootCA.pem cert/cafile_ts_fetch.ts",
+ output: "cert/cafile_ts_fetch.ts.out",
+ http_server: true,
+});
itest_flaky!(cafile_eval {
- args: "eval --cert tls/RootCA.pem fetch('https://localhost:5545/cert/cafile_ts_fetch.ts.out').then(r=>r.text()).then(t=>console.log(t.trimEnd()))",
- output: "cert/cafile_ts_fetch.ts.out",
- http_server: true,
- });
+ args: "eval --cert tls/RootCA.pem fetch('https://localhost:5545/cert/cafile_ts_fetch.ts.out').then(r=>r.text()).then(t=>console.log(t.trimEnd()))",
+ output: "cert/cafile_ts_fetch.ts.out",
+ http_server: true,
+});
itest_flaky!(cafile_info {
- args:
- "info --quiet --cert tls/RootCA.pem https://localhost:5545/cert/cafile_info.ts",
- output: "cert/cafile_info.ts.out",
- http_server: true,
- });
+ args:
+ "info --quiet --cert tls/RootCA.pem https://localhost:5545/cert/cafile_info.ts",
+ output: "cert/cafile_info.ts.out",
+ http_server: true,
+});
itest_flaky!(cafile_url_imports_unsafe_ssl {
- args: "run --quiet --reload --unsafely-ignore-certificate-errors=localhost cert/cafile_url_imports.ts",
- output: "cert/cafile_url_imports_unsafe_ssl.ts.out",
- http_server: true,
- });
+ args: "run --quiet --reload --unsafely-ignore-certificate-errors=localhost cert/cafile_url_imports.ts",
+ output: "cert/cafile_url_imports_unsafe_ssl.ts.out",
+ http_server: true,
+});
itest_flaky!(cafile_ts_fetch_unsafe_ssl {
- args:
- "run --quiet --reload --allow-net --unsafely-ignore-certificate-errors cert/cafile_ts_fetch.ts",
- output: "cert/cafile_ts_fetch_unsafe_ssl.ts.out",
- http_server: true,
- });
+ args:
+ "run --quiet --reload --allow-net --unsafely-ignore-certificate-errors cert/cafile_ts_fetch.ts",
+ output: "cert/cafile_ts_fetch_unsafe_ssl.ts.out",
+ http_server: true,
+});
// TODO(bartlomieju): reenable, this test was flaky on macOS CI during 1.30.3 release
// itest!(deno_land_unsafe_ssl {
-// args:
-// "run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=deno.land cert/deno_land_unsafe_ssl.ts",
-// output: "cert/deno_land_unsafe_ssl.ts.out",
-// });
+// args:
+// "run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=deno.land cert/deno_land_unsafe_ssl.ts",
+// output: "cert/deno_land_unsafe_ssl.ts.out",
+// });
itest!(ip_address_unsafe_ssl {
- args:
- "run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=1.1.1.1 cert/ip_address_unsafe_ssl.ts",
- output: "cert/ip_address_unsafe_ssl.ts.out",
- });
+ args:
+ "run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=1.1.1.1 cert/ip_address_unsafe_ssl.ts",
+ output: "cert/ip_address_unsafe_ssl.ts.out",
+});
itest!(localhost_unsafe_ssl {
- args:
- "run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=deno.land cert/cafile_url_imports.ts",
- output: "cert/localhost_unsafe_ssl.ts.out",
- http_server: true,
- exit_code: 1,
- });
+ args: "run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=deno.land cert/cafile_url_imports.ts",
+ output: "cert/localhost_unsafe_ssl.ts.out",
+ http_server: true,
+ exit_code: 1,
+});
#[flaky_test::flaky_test]
fn cafile_env_fetch() {
- use deno_core::url::Url;
- let _g = util::http_server();
- let deno_dir = TempDir::new();
let module_url =
Url::parse("https://localhost:5545/cert/cafile_url_imports.ts").unwrap();
- let cafile = util::testdata_path().join("tls/RootCA.pem");
- let output = Command::new(util::deno_exe_path())
- .env("DENO_DIR", deno_dir.path())
- .env("DENO_CERT", cafile)
- .current_dir(util::testdata_path())
- .arg("cache")
- .arg(module_url.to_string())
- .output()
- .expect("Failed to spawn script");
- assert!(output.status.success());
+ let context = TestContext::with_http_server();
+ let cafile = context.testdata_path().join("tls/RootCA.pem");
+ let output = context
+ .new_command()
+ .args(format!("cache {module_url}"))
+ .env("DENO_CERT", cafile.to_string_lossy())
+ .run();
+
+ assert_exit_code!(output, 0);
+ output.skip_output_check();
}
#[flaky_test::flaky_test]
fn cafile_fetch() {
- use deno_core::url::Url;
- let _g = util::http_server();
- let deno_dir = TempDir::new();
let module_url =
Url::parse("http://localhost:4545/cert/cafile_url_imports.ts").unwrap();
- let cafile = util::testdata_path().join("tls/RootCA.pem");
- let output = Command::new(util::deno_exe_path())
- .env("DENO_DIR", deno_dir.path())
- .current_dir(util::testdata_path())
- .arg("cache")
- .arg("--cert")
- .arg(cafile)
- .arg(module_url.to_string())
- .output()
- .expect("Failed to spawn script");
- assert!(output.status.success());
- let out = std::str::from_utf8(&output.stdout).unwrap();
- assert_eq!(out, "");
+ let context = TestContext::with_http_server();
+ let cafile = context.testdata_path().join("tls/RootCA.pem");
+ let output = context
+ .new_command()
+ .args(format!(
+ "cache --quiet --cert {} {}",
+ cafile.to_string_lossy(),
+ module_url,
+ ))
+ .run();
+
+ assert_exit_code!(output, 0);
+ assert_output_text!(output, "");
}
#[test]
fn cafile_compile() {
- let _g = util::http_server();
- let dir = TempDir::new();
- let exe = if cfg!(windows) {
- dir.path().join("cert.exe")
+ let context = TestContext::with_http_server();
+ let temp_dir = context.deno_dir().path();
+ let output_exe = if cfg!(windows) {
+ temp_dir.join("cert.exe")
} else {
- dir.path().join("cert")
+ temp_dir.join("cert")
};
- let output = util::deno_cmd()
- .current_dir(util::testdata_path())
- .arg("compile")
- .arg("--cert")
- .arg("./tls/RootCA.pem")
- .arg("--allow-net")
- .arg("--output")
- .arg(&exe)
- .arg("./cert/cafile_ts_fetch.ts")
- .stdout(std::process::Stdio::piped())
- .spawn()
- .unwrap()
- .wait_with_output()
- .unwrap();
- assert!(output.status.success());
- let output = Command::new(exe)
- .stdout(std::process::Stdio::piped())
- .spawn()
- .unwrap()
- .wait_with_output()
- .unwrap();
- assert!(output.status.success());
- assert_eq!(output.stdout, b"[WILDCARD]\nHello\n")
+ let output = context.new_command()
+ .args(format!("compile --quiet --cert ./tls/RootCA.pem --allow-net --output {} ./cert/cafile_ts_fetch.ts", output_exe.to_string_lossy()))
+ .run();
+ output.skip_output_check();
+
+ let exe_output = context
+ .new_command()
+ .command_name(output_exe.to_string_lossy())
+ .run();
+
+ assert_output_text!(exe_output, "[WILDCARD]\nHello\n");
}
#[flaky_test::flaky_test]
diff --git a/cli/tests/integration/lint_tests.rs b/cli/tests/integration/lint_tests.rs
index 990db16b6..8bf35ed8f 100644
--- a/cli/tests/integration/lint_tests.rs
+++ b/cli/tests/integration/lint_tests.rs
@@ -1,26 +1,10 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-use test_util as util;
-
-#[test]
-fn ignore_unexplicit_files() {
- let output = util::deno_cmd()
- .current_dir(util::root_path())
- .env("NO_COLOR", "1")
- .arg("lint")
- .arg("--unstable")
- .arg("--ignore=./")
- .stderr(std::process::Stdio::piped())
- .spawn()
- .unwrap()
- .wait_with_output()
- .unwrap();
- assert!(!output.status.success());
- assert_eq!(
- String::from_utf8_lossy(&output.stderr),
- "error: No target files found.\n"
- );
-}
+itest!(ignore_unexplicit_files {
+ args: "lint --unstable --ignore=./",
+ output_str: Some("error: No target files found.\n"),
+ exit_code: 1,
+});
itest!(all {
args: "lint lint/without_config/file1.js lint/without_config/file2.ts lint/without_config/ignored_file.ts",
diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs
index d102b486d..6d1daf7d7 100644
--- a/cli/tests/integration/mod.rs
+++ b/cli/tests/integration/mod.rs
@@ -5,12 +5,20 @@ macro_rules! itest(
($name:ident {$( $key:ident: $value:expr,)*}) => {
#[test]
fn $name() {
- (test_util::CheckOutputIntegrationTest {
+ let test = test_util::CheckOutputIntegrationTest {
$(
$key: $value,
)*
.. Default::default()
- }).run()
+ };
+ let output = test.output();
+ test_util::assert_exit_code!(output, test.exit_code);
+ if !test.output.is_empty() {
+ assert!(test.output_str.is_none());
+ test_util::assert_output_file!(output, test.output);
+ } else {
+ test_util::assert_output_text!(output, test.output_str.unwrap_or(""));
+ }
}
}
);
@@ -20,7 +28,42 @@ macro_rules! itest_flaky(
($name:ident {$( $key:ident: $value:expr,)*}) => {
#[flaky_test::flaky_test]
fn $name() {
- (test_util::CheckOutputIntegrationTest {
+ let test = test_util::CheckOutputIntegrationTest {
+ $(
+ $key: $value,
+ )*
+ .. Default::default()
+ };
+ let output = test.output();
+ test_util::assert_exit_code!(output, test.exit_code);
+ if !test.output.is_empty() {
+ assert!(test.output_str.is_none());
+ test_util::assert_output_file!(output, test.output);
+ } else {
+ test_util::assert_output_text!(output, test.output_str.unwrap_or(""));
+ }
+ }
+}
+);
+
+#[macro_export]
+macro_rules! context(
+({$( $key:ident: $value:expr,)*}) => {
+ test_util::TestContext::create(test_util::TestContextOptions {
+ $(
+ $key: $value,
+ )*
+ .. Default::default()
+ })
+}
+);
+
+#[macro_export]
+macro_rules! itest_steps(
+($name:ident {$( $key:ident: $value:expr,)*}) => {
+ #[test]
+ fn $name() {
+ (test_util::CheckOutputIntegrationTestSteps {
$(
$key: $value,
)*
@@ -30,6 +73,18 @@ macro_rules! itest_flaky(
}
);
+#[macro_export]
+macro_rules! command_step(
+({$( $key:ident: $value:expr,)*}) => {
+ test_util::CheckOutputIntegrationTestCommandStep {
+ $(
+ $key: $value,
+ )*
+ .. Default::default()
+ }
+}
+);
+
// These files have `_tests.rs` suffix to make it easier to tell which file is
// the test (ex. `lint_tests.rs`) and which is the implementation (ex. `lint.rs`)
// when both are open, especially for two tabs in VS Code
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index d52109d2b..0ff09e69d 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -2,7 +2,9 @@
use deno_core::url::Url;
use test_util as util;
+use util::assert_output_file;
use util::env_vars_for_npm_tests;
+use util::TestContext;
#[test]
fn no_color() {
@@ -414,13 +416,9 @@ fn file_protocol() {
.unwrap()
.to_string();
- (util::CheckOutputIntegrationTest {
- args_vec: vec!["test", &file_url],
- exit_code: 0,
- output: "test/file_protocol.out",
- ..Default::default()
- })
- .run();
+ let context = TestContext::default();
+ let output = context.new_command().args(format!("test {file_url}")).run();
+ assert_output_file!(output, "test/file_protocol.out");
}
itest!(uncaught_errors {