diff options
Diffstat (limited to 'cli/tests/integration_tests.rs')
-rw-r--r-- | cli/tests/integration_tests.rs | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index ac00a04c4..dd242a32a 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -603,6 +603,32 @@ itest!(bundle { output: "bundle.test.out", }); +itest!(fmt_stdin { + args: "fmt -", + input: Some("const a = 1\n"), + output_str: Some("const a = 1;\n"), +}); + +itest!(fmt_stdin_ambiguous { + args: "fmt - file.ts", + input: Some("const a = 1\n"), + check_stderr: true, + exit_code: 1, + output_str: Some("Ambiguous filename input. To format stdin, provide a single '-' instead.\n"), +}); + +itest!(fmt_stdin_check_formatted { + args: "fmt --check -", + input: Some("const a = 1;\n"), + output_str: Some(""), +}); + +itest!(fmt_stdin_check_not_formatted { + args: "fmt --check -", + input: Some("const a = 1\n"), + output_str: Some("Not formatted stdin\n"), +}); + itest!(circular1 { args: "run --reload circular1.js", output: "circular1.js.out", @@ -917,6 +943,7 @@ mod util { pub args: &'static str, pub output: &'static str, pub input: Option<&'static str>, + pub output_str: Option<&'static str>, pub exit_code: i32, pub check_stderr: bool, pub http_server: bool, @@ -982,10 +1009,13 @@ mod util { ); } - let output_path = tests_dir.join(self.output); - println!("output path {}", output_path.display()); - let expected = - std::fs::read_to_string(output_path).expect("cannot read output"); + let expected = if let Some(s) = self.output_str { + s.to_owned() + } else { + let output_path = tests_dir.join(self.output); + println!("output path {}", output_path.display()); + std::fs::read_to_string(output_path).expect("cannot read output") + }; if !wildcard_match(&expected, &actual) { println!("OUTPUT\n{}\nOUTPUT", actual); |