2019-02-01 18:29:00 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import os
|
|
|
|
import shutil
|
2019-05-30 16:40:40 -04:00
|
|
|
|
2019-06-03 12:35:55 -04:00
|
|
|
from test_util import DenoTestCase, run_tests
|
2019-06-08 07:46:57 -04:00
|
|
|
from util import mkdtemp, root_path, tests_path, run_output
|
2019-02-01 18:29:00 -05:00
|
|
|
|
|
|
|
|
2019-06-08 07:46:57 -04:00
|
|
|
class TestFmt(DenoTestCase):
|
2019-05-30 16:40:40 -04:00
|
|
|
def test_fmt(self):
|
|
|
|
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)
|
2019-05-28 16:33:32 -04:00
|
|
|
|
2019-05-30 16:40:40 -04:00
|
|
|
# Set DENO_DIR to the temp dir to test an initial fetch of prettier.
|
|
|
|
# TODO(ry) This make the test depend on internet access which is not
|
|
|
|
# ideal. We should have prettier in the repo already, and we could
|
|
|
|
# fetch it instead through tools/http_server.py.
|
|
|
|
deno_dir = d
|
2019-03-28 16:05:41 -04:00
|
|
|
|
2019-05-30 16:40:40 -04:00
|
|
|
# TODO(kt3k) Below can be run([deno_exe, "fmt", dst], ...)
|
|
|
|
# once the following issue is addressed:
|
|
|
|
# https://github.com/denoland/deno_std/issues/330
|
2019-06-08 07:46:57 -04:00
|
|
|
result = run_output([
|
2019-05-30 16:40:40 -04:00
|
|
|
os.path.join(root_path, self.deno_exe), "fmt",
|
|
|
|
"badly_formatted.js"
|
|
|
|
],
|
2019-06-08 07:46:57 -04:00
|
|
|
cwd=d,
|
|
|
|
merge_env={"DENO_DIR": deno_dir},
|
|
|
|
exit_on_fail=True,
|
|
|
|
quiet=True)
|
|
|
|
self.assertEqual(result.code, 0)
|
2019-05-30 16:40:40 -04:00
|
|
|
with open(fixed_filename) as f:
|
|
|
|
expected = f.read()
|
|
|
|
with open(dst) as f:
|
|
|
|
actual = f.read()
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(d)
|
2019-02-01 18:29:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-06-03 12:35:55 -04:00
|
|
|
run_tests()
|