diff options
author | uki00a <uki00a@gmail.com> | 2020-05-15 23:22:28 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-15 10:22:28 -0400 |
commit | c5a54e44bc0a697b45efb98d3f5d1dc751efe49f (patch) | |
tree | 7ab813e56f0e7492b785655b9585d5f92b6bb928 | |
parent | b0d62cdbd79a8dfcbe9ef8539fe2efae3f21890b (diff) |
chore: port deno_dir_test to Rust (#5408)
-rw-r--r-- | cli/tests/integration_tests.rs | 35 | ||||
-rwxr-xr-x | tools/deno_dir_test.py | 52 |
2 files changed, 34 insertions, 53 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 8c31c1408..db9ccafd7 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -146,8 +146,41 @@ fn benchmark_test() { #[test] fn deno_dir_test() { + use std::fs::remove_dir_all; let g = util::http_server(); - util::run_python_script("tools/deno_dir_test.py"); + let deno_dir = TempDir::new().expect("tempdir fail"); + remove_dir_all(deno_dir.path()).unwrap(); + + // Run deno with no env flag + let status = util::deno_cmd() + .env_remove("DENO_DIR") + .current_dir(util::root_path()) + .arg("run") + .arg("http://localhost:4545/cli/tests/subdir/print_hello.ts") + .spawn() + .expect("Failed to spawn script") + .wait() + .expect("Failed to wait for child process"); + assert!(status.success()); + assert!(!deno_dir.path().exists()); + + // Run deno with DENO_DIR env flag + let status = util::deno_cmd() + .env("DENO_DIR", deno_dir.path()) + .current_dir(util::root_path()) + .arg("run") + .arg("http://localhost:4545/cli/tests/subdir/print_hello.ts") + .spawn() + .expect("Failed to spawn script") + .wait() + .expect("Failed to wait for child process"); + assert!(status.success()); + assert!(deno_dir.path().is_dir()); + assert!(deno_dir.path().join("deps").is_dir()); + assert!(deno_dir.path().join("gen").is_dir()); + + remove_dir_all(deno_dir.path()).unwrap(); + drop(deno_dir); drop(g); } diff --git a/tools/deno_dir_test.py b/tools/deno_dir_test.py deleted file mode 100755 index 9e11b8e3b..000000000 --- a/tools/deno_dir_test.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -# Check deno dir is created properly -# Usage: deno_dir_test.py [path to deno dir] -import os - -from test_util import DenoTestCase, run_tests -from util import mkdtemp, rmtree, run_output - - -class TestDenoDir(DenoTestCase): - def setUp(self): - self.old_deno_dir = None - if "DENO_DIR" in os.environ: - self.old_deno_dir = os.environ["DENO_DIR"] - del os.environ["DENO_DIR"] - - def tearDown(self): - if self.old_deno_dir is not None: - os.environ["DENO_DIR"] = self.old_deno_dir - - def test_deno_dir(self): - deno_dir = mkdtemp() - if os.path.isdir(deno_dir): - rmtree(deno_dir) - - # Run deno with no env flag - self.run_deno() - assert not os.path.isdir(deno_dir) - - # TODO(bartlomieju): reenable or rewrite these tests - # now all cache directories are lazily created - # Run deno with DENO_DIR env flag - # self.run_deno(deno_dir) - # assert os.path.isdir(deno_dir) - # assert os.path.isdir(os.path.join(deno_dir, "deps")) - # assert os.path.isdir(os.path.join(deno_dir, "gen")) - # rmtree(deno_dir) - - def run_deno(self, deno_dir=None): - cmd = [ - self.deno_exe, "run", - "http://localhost:4545/cli/tests/subdir/print_hello.ts" - ] - deno_dir_env = {"DENO_DIR": deno_dir} if deno_dir is not None else None - res = run_output(cmd, quiet=True, env=deno_dir_env) - print res.code, res.out, res.err - self.assertEqual(res.code, 0) - - -if __name__ == '__main__': - run_tests() |