summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-05-08 22:45:06 -0400
committerGitHub <noreply@github.com>2024-05-08 22:45:06 -0400
commit47f7bed677a6b72e873712de8f3988ea891710e4 (patch)
tree096549459b479cf1383e65c87b77e9f9482df258 /tests
parente6dc4dfbff25e77d2127591802229b4a74037d24 (diff)
chore: enable clippy::print_stdout and clippy::print_stderr (#23732)
1. Generally we should prefer to use the `log` crate. 2. I very often accidentally commit `eprintln`s. When we should use `println` or `eprintln`, it's not too bad to be a bit more verbose and ignore the lint rule.
Diffstat (limited to 'tests')
-rw-r--r--tests/ffi/src/lib.rs2
-rw-r--r--tests/ffi/tests/integration_tests.rs3
-rw-r--r--tests/integration/inspector_tests.rs40
-rw-r--r--tests/integration/mod.rs3
-rw-r--r--tests/napi/src/lib.rs3
-rw-r--r--tests/napi/tests/napi_tests.rs7
-rw-r--r--tests/testdata/inspector/inspector_test.js5
-rw-r--r--tests/util/server/src/lib.rs3
-rw-r--r--tests/util/server/src/test_server.rs3
9 files changed, 47 insertions, 22 deletions
diff --git a/tests/ffi/src/lib.rs b/tests/ffi/src/lib.rs
index f6ee31eb8..09c2afb3d 100644
--- a/tests/ffi/src/lib.rs
+++ b/tests/ffi/src/lib.rs
@@ -1,5 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
#![allow(clippy::undocumented_unsafe_blocks)]
use std::os::raw::c_void;
diff --git a/tests/ffi/tests/integration_tests.rs b/tests/ffi/tests/integration_tests.rs
index 0ad95254c..d0ac6e104 100644
--- a/tests/ffi/tests/integration_tests.rs
+++ b/tests/ffi/tests/integration_tests.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
+
use pretty_assertions::assert_eq;
use std::process::Command;
use test_util::deno_cmd;
diff --git a/tests/integration/inspector_tests.rs b/tests/integration/inspector_tests.rs
index d18375a83..6a0f9111e 100644
--- a/tests/integration/inspector_tests.rs
+++ b/tests/integration/inspector_tests.rs
@@ -21,6 +21,7 @@ use test_util as util;
use tokio::net::TcpStream;
use tokio::time::timeout;
use url::Url;
+use util::assert_contains;
use util::assert_starts_with;
use util::DenoChild;
use util::TestContextBuilder;
@@ -94,12 +95,18 @@ impl InspectorTester {
F: FnMut(&str) -> bool + 'static,
{
let stdout = child.stdout.take().unwrap();
- let stdout_lines =
- std::io::BufReader::new(stdout).lines().map(|r| r.unwrap());
+ let stdout_lines = std::io::BufReader::new(stdout).lines().map(|r| {
+ let line = r.unwrap();
+ eprintln!("STDOUT: {}", line);
+ line
+ });
let stderr = child.stderr.take().unwrap();
- let mut stderr_lines =
- std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());
+ let mut stderr_lines = std::io::BufReader::new(stderr).lines().map(|r| {
+ let line = r.unwrap();
+ eprintln!("STDERR: {}", line);
+ line
+ });
let uri = extract_ws_url_from_stderr(&mut stderr_lines);
@@ -810,7 +817,6 @@ async fn inspector_break_on_first_line_in_test() {
let script = util::testdata_path().join("inspector/inspector_test.js");
let child = util::deno_cmd()
.arg("test")
- .arg("--quiet")
.arg(inspect_flag_with_unique_port("--inspect-brk"))
.arg(script)
.env("NO_COLOR", "1")
@@ -877,10 +883,7 @@ async fn inspector_break_on_first_line_in_test() {
assert_starts_with!(&tester.stdout_line(), "running 1 test from");
let line = tester.stdout_line();
- assert!(
- &line.contains("basic test ... ok"),
- "Missing content: {line}"
- );
+ assert_contains!(line, "basic test ... ok");
tester.child.kill().unwrap();
tester.child.wait().unwrap();
@@ -907,6 +910,7 @@ async fn inspector_with_ts_files() {
let mut tester = InspectorTester::create(child, notification_filter).await;
tester.assert_stderr_for_inspect_brk();
+ assert_eq!(&tester.stderr_line(), "Debugger session started.");
tester
.send_many(&[
@@ -926,19 +930,19 @@ async fn inspector_with_ts_files() {
// receive messages with sources from this test
let script1 = tester.recv().await;
- assert!(script1.contains("testdata/inspector/test.ts"));
+ assert_contains!(script1, "testdata/inspector/test.ts");
let script1_id = {
let v: serde_json::Value = serde_json::from_str(&script1).unwrap();
v["params"]["scriptId"].as_str().unwrap().to_string()
};
let script2 = tester.recv().await;
- assert!(script2.contains("testdata/inspector/foo.ts"));
+ assert_contains!(script2, "testdata/inspector/foo.ts");
let script2_id = {
let v: serde_json::Value = serde_json::from_str(&script2).unwrap();
v["params"]["scriptId"].as_str().unwrap().to_string()
};
let script3 = tester.recv().await;
- assert!(script3.contains("testdata/inspector/bar.js"));
+ assert_contains!(script3, "testdata/inspector/bar.js");
let script3_id = {
let v: serde_json::Value = serde_json::from_str(&script3).unwrap();
v["params"]["scriptId"].as_str().unwrap().to_string()
@@ -996,10 +1000,12 @@ async fn inspector_with_ts_files() {
)
.await;
+ let line = tester.stderr_line();
+ assert_contains!(test_util::strip_ansi_codes(&line), "Check");
assert_eq!(
- &tester.stdout_line(),
- "Program finished. Waiting for inspector to disconnect to exit the process..."
- );
+ &tester.stderr_line(),
+ "Program finished. Waiting for inspector to disconnect to exit the process..."
+ );
tester.child.kill().unwrap();
tester.child.wait().unwrap();
@@ -1194,7 +1200,6 @@ async fn inspector_break_on_first_line_npm_esm() {
.new_command()
.args_vec([
"run",
- "--quiet",
&inspect_flag_with_unique_port("--inspect-brk"),
"npm:@denotest/bin/cli-esm",
"this",
@@ -1262,7 +1267,6 @@ async fn inspector_break_on_first_line_npm_cjs() {
.new_command()
.args_vec([
"run",
- "--quiet",
&inspect_flag_with_unique_port("--inspect-brk"),
"npm:@denotest/bin/cli-cjs",
"this",
@@ -1331,7 +1335,6 @@ async fn inspector_error_with_npm_import() {
.new_command()
.args_vec([
"run",
- "--quiet",
"-A",
&inspect_flag_with_unique_port("--inspect-brk"),
&script.to_string_lossy(),
@@ -1394,7 +1397,6 @@ async fn inspector_wait() {
.new_command()
.args_vec([
"run",
- "--quiet",
"-A",
&inspect_flag_with_unique_port("--inspect-wait"),
&script.to_string_lossy(),
diff --git a/tests/integration/mod.rs b/tests/integration/mod.rs
index 30cc9a791..59bf0db37 100644
--- a/tests/integration/mod.rs
+++ b/tests/integration/mod.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
+
// 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/tests/napi/src/lib.rs b/tests/napi/src/lib.rs
index 1b9246483..f6fe6e189 100644
--- a/tests/napi/src/lib.rs
+++ b/tests/napi/src/lib.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
#![allow(clippy::all)]
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
#![allow(clippy::undocumented_unsafe_blocks)]
use std::ffi::c_void;
diff --git a/tests/napi/tests/napi_tests.rs b/tests/napi/tests/napi_tests.rs
index 671699651..1c9b1ba94 100644
--- a/tests/napi/tests/napi_tests.rs
+++ b/tests/napi/tests/napi_tests.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
+
use std::process::Command;
use test_util::deno_cmd;
use test_util::deno_config_path;
@@ -80,8 +83,8 @@ fn napi_tests() {
if !output.status.success() {
eprintln!("exit code {:?}", output.status.code());
- println!("stdout {stdout}");
- println!("stderr {stderr}");
+ println!("stdout {}", stdout);
+ println!("stderr {}", stderr);
}
assert!(output.status.success());
}
diff --git a/tests/testdata/inspector/inspector_test.js b/tests/testdata/inspector/inspector_test.js
index 86cd48854..e1ac7b635 100644
--- a/tests/testdata/inspector/inspector_test.js
+++ b/tests/testdata/inspector/inspector_test.js
@@ -1,3 +1,6 @@
Deno.test("basic test", () => {
- console.log("test has finished running");
+ const value = 1 + 1;
+ if (value !== 2) {
+ throw new Error("failed");
+ }
});
diff --git a/tests/util/server/src/lib.rs b/tests/util/server/src/lib.rs
index ec9154af2..ee5348049 100644
--- a/tests/util/server/src/lib.rs
+++ b/tests/util/server/src/lib.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
+
use std::collections::HashMap;
use std::env;
use std::io::Write;
diff --git a/tests/util/server/src/test_server.rs b/tests/util/server/src/test_server.rs
index 19e33f9f5..3ae3eaa7d 100644
--- a/tests/util/server/src/test_server.rs
+++ b/tests/util/server/src/test_server.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
+
fn main() {
setup_panic_hook();
test_server::servers::run_all_servers();