summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/fmt_test.py34
-rwxr-xr-xtools/prefetch_test.py9
-rwxr-xr-xtools/test.py2
-rw-r--r--tools/util.py8
4 files changed, 46 insertions, 7 deletions
diff --git a/tools/fmt_test.py b/tools/fmt_test.py
new file mode 100755
index 000000000..95733dc20
--- /dev/null
+++ b/tools/fmt_test.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+import os
+import sys
+from util import mkdtemp, root_path, tests_path, run, green_ok
+import shutil
+
+
+def fmt_test(deno_exe):
+ sys.stdout.write("fmt_test...")
+ sys.stdout.flush()
+ d = mkdtemp()
+ try:
+ fixed_filename = os.path.join(tests_path, "badly_formatted_fixed.js")
+ src = os.path.join(tests_path, "badly_formatted.js")
+ dst = os.path.join(d, "badly_formatted.js")
+ shutil.copyfile(src, dst)
+ # Set DENO_DIR to //js/ so we don't have to rely on an intenet
+ # connection to download https://deno.land/x/std/prettier/main.ts
+ deno_dir = os.path.join(root_path, "js")
+ run([deno_exe, dst, "--fmt"], merge_env={"DENO_DIR": deno_dir})
+ with open(fixed_filename) as f:
+ expected = f.read()
+ with open(dst) as f:
+ actual = f.read()
+ assert expected == actual
+ finally:
+ shutil.rmtree(d)
+ print green_ok()
+
+
+if __name__ == "__main__":
+ fmt_test(sys.argv[1])
+
diff --git a/tools/prefetch_test.py b/tools/prefetch_test.py
index bc106d5f5..3024aedf3 100755
--- a/tools/prefetch_test.py
+++ b/tools/prefetch_test.py
@@ -2,8 +2,7 @@
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import os
import sys
-from util import tests_path, run_output, build_path, executable_suffix, green_ok
-import tempfile
+from util import mkdtemp, tests_path, run_output, green_ok
import shutil
@@ -11,11 +10,7 @@ def prefetch_test(deno_exe):
sys.stdout.write("prefetch_test...")
sys.stdout.flush()
- # On Windows, set the base directory that mkdtemp() uses explicitly. If not,
- # it'll use the short (8.3) path to the temp dir, which triggers the error
- # 'TS5009: Cannot find the common subdirectory path for the input files.'
- temp_dir = os.environ["TEMP"] if os.name == 'nt' else None
- deno_dir = tempfile.mkdtemp(dir=temp_dir)
+ deno_dir = mkdtemp()
try:
t = os.path.join(tests_path, "006_url_imports.ts")
output = run_output([deno_exe, "--prefetch", t],
diff --git a/tools/test.py b/tools/test.py
index 614395b71..8da13b01a 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -13,6 +13,7 @@ from util_test import util_test
from benchmark_test import benchmark_test
from repl_test import repl_tests
from prefetch_test import prefetch_test
+from fmt_test import fmt_test
import subprocess
import http_server
@@ -61,6 +62,7 @@ def main(argv):
unit_tests(deno_exe)
prefetch_test(deno_exe)
+ fmt_test(deno_exe)
integration_tests(deno_exe)
diff --git a/tools/util.py b/tools/util.py
index a4355b41f..ca18faf54 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -5,6 +5,7 @@ import shutil
import stat
import sys
import subprocess
+import tempfile
RESET = "\x1b[0m"
FG_RED = "\x1b[31m"
@@ -381,3 +382,10 @@ def parse_wrk_output(output):
def platform():
return {"linux2": "linux", "darwin": "mac", "win32": "win"}[sys.platform]
+
+def mkdtemp():
+ # On Windows, set the base directory that mkdtemp() uses explicitly. If not,
+ # it'll use the short (8.3) path to the temp dir, which triggers the error
+ # 'TS5009: Cannot find the common subdirectory path for the input files.'
+ temp_dir = os.environ["TEMP"] if os.name == 'nt' else None
+ return tempfile.mkdtemp(dir=temp_dir)