test_format.py 1.1 KB
Newer Older
1
#!/usr/bin/env python
2 3
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
# This program fails if ./tools/format.ts changes any files.
4

5
import os
6 7 8 9
import sys
import util
import sys
import subprocess
10 11 12 13 14 15 16 17 18 19 20 21 22 23
from distutils.spawn import find_executable


def lookup_deno_path():
    deno_exe = "deno" + util.executable_suffix
    release_deno = os.path.join(util.root_path, "target", "release", deno_exe)
    debug_deno = os.path.join(util.root_path, "target", "debug", deno_exe)

    if os.path.exists(release_deno):
        return release_deno
    if os.path.exists(debug_deno):
        return debug_deno

    return find_executable("deno")
24 25


R
Ryan Dahl 已提交
26
def main():
27 28 29 30 31 32
    deno_path = lookup_deno_path()

    if not deno_path:
        print "No available deno executable."
        sys.exit(1)

D
Dmitry Sharshakov 已提交
33
    util.run([deno_path, "--allow-read", "--allow-run", "tools/format.ts"])
34 35 36
    output = util.run_output(
        ["git", "status", "-uno", "--porcelain", "--ignore-submodules"])
    if len(output) > 0:
37
        print "Run tools/format.ts "
38 39 40 41 42
        print output
        sys.exit(1)


if __name__ == '__main__':
R
Ryan Dahl 已提交
43
    main()