summaryrefslogtreecommitdiff
path: root/cli/tests/integration_tests.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-01-30 03:16:48 +0100
committerGitHub <noreply@github.com>2020-01-29 21:16:48 -0500
commit73a3cc21d0e7ceec1275078db125f57ce97725fb (patch)
tree17d845d5d125d3ba8ecefa49e57e02e9c088c68b /cli/tests/integration_tests.rs
parentf0a6062012c4e09553877c9feedb3fbc3d4625b9 (diff)
feat: dprint formatter (#3820)
* rewrite fmt_test in Rust, remove tools/fmt_test.py * remove //std/prettier
Diffstat (limited to 'cli/tests/integration_tests.rs')
-rw-r--r--cli/tests/integration_tests.rs40
1 files changed, 36 insertions, 4 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 7f318119a..501ff1713 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -29,12 +29,44 @@ fn fetch_test() {
drop(g);
}
-// TODO(#2933): Rewrite this test in rust.
#[test]
fn fmt_test() {
- let g = util::http_server();
- util::run_python_script("tools/fmt_test.py");
- drop(g);
+ use tempfile::TempDir;
+
+ let t = TempDir::new().expect("tempdir fail");
+ let fixed = util::root_path().join("cli/tests/badly_formatted_fixed.js");
+ let badly_formatted_original =
+ util::root_path().join("cli/tests/badly_formatted.js");
+ let badly_formatted = t.path().join("badly_formatted.js");
+ let badly_formatted_str = badly_formatted.to_str().unwrap();
+ std::fs::copy(&badly_formatted_original, &badly_formatted)
+ .expect("Failed to copy file");
+
+ let status = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("fmt")
+ .arg("--check")
+ .arg(badly_formatted_str)
+ .spawn()
+ .expect("Failed to spawn script")
+ .wait()
+ .expect("Failed to wait for child process");
+
+ assert_eq!(Some(1), status.code());
+
+ let status = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("fmt")
+ .arg(badly_formatted_str)
+ .spawn()
+ .expect("Failed to spawn script")
+ .wait()
+ .expect("Failed to wait for child process");
+
+ assert_eq!(Some(0), status.code());
+ let expected = std::fs::read_to_string(fixed).unwrap();
+ let actual = std::fs::read_to_string(badly_formatted).unwrap();
+ assert_eq!(expected, actual);
}
#[test]