diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2020-02-09 02:19:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-09 11:19:05 +0100 |
commit | 506601841218fe34a744c8fce0f1011c716bdc73 (patch) | |
tree | 1b80e06ec5cd1385ea4aaabb060b83701d47b4bb /cli/tests/integration_tests.rs | |
parent | 1c0ffa138355c7eb90fd5d3c01f799245636bcc0 (diff) |
fmt: `deno fmt -` formats stdin and print to stdout (#3920)
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); |