fix: improve formatting (#1732)

This commit is contained in:
Yoshiya Hinosawa 2019-02-12 02:57:26 +09:00 committed by Ryan Dahl
parent 90c7af27d7
commit d26655371b
17 changed files with 55 additions and 30 deletions

View file

@ -18,6 +18,7 @@ environment:
RUSTUP_HOME: $(RUST_DIR)\rustup RUSTUP_HOME: $(RUST_DIR)\rustup
RUST_BACKTRACE: full RUST_BACKTRACE: full
RUSTC_WRAPPER: sccache RUSTC_WRAPPER: sccache
PYTHONPATH: third_party\python_packages
SCCACHE_BUCKET: deno-sccache SCCACHE_BUCKET: deno-sccache
AWS_ACCESS_KEY_ID: AKIAIVRN52PLDBP55LBQ AWS_ACCESS_KEY_ID: AKIAIVRN52PLDBP55LBQ
AWS_SECRET_ACCESS_KEY: AWS_SECRET_ACCESS_KEY:

View file

@ -19,7 +19,8 @@ Before submitting, please make sure the following is done:
1. There are tests that cover the changes. 1. There are tests that cover the changes.
2. Ensure `./tools/test.py` passes. 2. Ensure `./tools/test.py` passes.
3. Format your code with `deno ./tools/format.ts --allow-read --allow-run`. 3. Format your code with `PYTHONPATH=third_party/python_packages deno ./tools/format.ts --allow-read --allow-run`.
<!-- TODO: set PYTHONPATH in format.ts when run API has env option -->
4. Make sure `./tools/lint.py` passes. 4. Make sure `./tools/lint.py` passes.
## Changes to `third_party` ## Changes to `third_party`

View file

@ -10,6 +10,7 @@ env:
- RUST_BACKTRACE=full - RUST_BACKTRACE=full
- CARGO_TARGET_DIR=$HOME/target - CARGO_TARGET_DIR=$HOME/target
- PATH=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin:$CARGO_HOME/bin:$PATH - PATH=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin:$CARGO_HOME/bin:$PATH
- PYTHONPATH=third_party/python_packages
- RUSTC_WRAPPER=sccache - RUSTC_WRAPPER=sccache
- SCCACHE_BUCKET=deno-sccache - SCCACHE_BUCKET=deno-sccache
- AWS_ACCESS_KEY_ID=AKIAIVRN52PLDBP55LBQ - AWS_ACCESS_KEY_ID=AKIAIVRN52PLDBP55LBQ

View file

@ -116,7 +116,8 @@ Extra steps for Windows users:
./tools/test.py ./tools/test.py
# Format code. # Format code.
deno ./tools/format.ts --allow-read --allow-run PYTHONPATH=third_party/python_packages deno ./tools/format.ts --allow-read --allow-run
<!-- TODO: set PYTHONPATH in format.ts when run API has env option -->
Other useful commands: Other useful commands:

View file

@ -245,8 +245,11 @@ test(function consoleTestError() {
try { try {
throw new MyError("This is an error"); throw new MyError("This is an error");
} catch (e) { } catch (e) {
assert(stringify(e).split("\n")[3] assert(
.includes("MyError: This is an error")); stringify(e)
.split("\n")[3]
.includes("MyError: This is an error")
);
} }
}); });

View file

@ -107,7 +107,8 @@ function evaluate(code: string): void {
} else { } else {
if (errInfo.isNativeError) { if (errInfo.isNativeError) {
const formattedError = formatError( const formattedError = formatError(
libdeno.errorToJSON(errInfo.thrown as Error)); libdeno.errorToJSON(errInfo.thrown as Error)
);
console.error(formattedError); console.error(formattedError);
} else { } else {
console.error("Thrown:", errInfo.thrown); console.error("Thrown:", errInfo.thrown);

View file

@ -57,15 +57,20 @@ def import_data_from_gh_pages():
def get_binary_sizes(build_dir): def get_binary_sizes(build_dir):
path_dict = { path_dict = {
"deno": os.path.join(build_dir, "deno" + executable_suffix), "deno":
"main.js": os.path.join(build_dir, "gen/bundle/main.js"), os.path.join(build_dir, "deno" + executable_suffix),
"main.js.map": os.path.join(build_dir, "gen/bundle/main.js.map"), "main.js":
"compiler.js": os.path.join(build_dir, "gen/bundle/compiler.js"), os.path.join(build_dir, "gen/bundle/main.js"),
"compiler.js.map": os.path.join(build_dir, "main.js.map":
"gen/bundle/compiler.js.map"), os.path.join(build_dir, "gen/bundle/main.js.map"),
"snapshot_deno.bin": os.path.join(build_dir, "gen/snapshot_deno.bin"), "compiler.js":
"snapshot_compiler.bin": os.path.join(build_dir, os.path.join(build_dir, "gen/bundle/compiler.js"),
"gen/snapshot_compiler.bin") "compiler.js.map":
os.path.join(build_dir, "gen/bundle/compiler.js.map"),
"snapshot_deno.bin":
os.path.join(build_dir, "gen/snapshot_deno.bin"),
"snapshot_compiler.bin":
os.path.join(build_dir, "gen/snapshot_compiler.bin")
} }
sizes = {} sizes = {}
for name, path in path_dict.items(): for name, path in path_dict.items():

View file

@ -18,8 +18,7 @@ def fmt_test(deno_exe):
# Set DENO_DIR to //js/ so we don't have to rely on an intenet # 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 # connection to download https://deno.land/x/std/prettier/main.ts
deno_dir = os.path.join(root_path, "js") deno_dir = os.path.join(root_path, "js")
run( run([deno_exe, dst, "--fmt", "--allow-read"],
[deno_exe, dst, "--fmt", "--allow-read"],
merge_env={"DENO_DIR": deno_dir}) merge_env={"DENO_DIR": deno_dir})
with open(fixed_filename) as f: with open(fixed_filename) as f:
expected = f.read() expected = f.read()

View file

@ -10,12 +10,20 @@ const yapf = join("third_party", "python_packages", "bin", "yapf");
const rustfmt = join("third_party", "rustfmt", deno.platform.os, "rustfmt"); const rustfmt = join("third_party", "rustfmt", deno.platform.os, "rustfmt");
const rustfmtConfig = ".rustfmt.toml"; const rustfmtConfig = ".rustfmt.toml";
const run = (...args: string[]) => { const decoder = new TextDecoder();
async function run(...args: string[]): Promise<void> {
if (deno.platform.os === "win") { if (deno.platform.os === "win") {
args = ["cmd.exe", "/c", ...args]; args = ["cmd.exe", "/c", ...args];
} }
return deno.run({ args, stdout: "null", stderr: "piped" }).status(); const p = deno.run({ args, stdout: "piped", stderr: "piped" });
}; const { code } = await p.status();
if (code !== 0) {
console.log(decoder.decode(await deno.readAll(p.stderr)));
console.log(decoder.decode(await deno.readAll(p.stdout)));
deno.exit(code);
}
}
(async () => { (async () => {
console.log("clang_format"); console.log("clang_format");
@ -49,6 +57,7 @@ const run = (...args: string[]) => {
console.log("prettier"); console.log("prettier");
await run( await run(
lookupDenoPath(), lookupDenoPath(),
"--allow-read",
"--allow-write", "--allow-write",
"js/deps/https/deno.land/x/std/prettier/main.ts", "js/deps/https/deno.land/x/std/prettier/main.ts",
"rollup.config.js", "rollup.config.js",

View file

@ -45,7 +45,7 @@ def str2bool(v):
raise ValueError("Bad boolean value") raise ValueError("Bad boolean value")
def integration_tests(deno_exe, test_filter = None): def integration_tests(deno_exe, test_filter=None):
assert os.path.isfile(deno_exe) assert os.path.isfile(deno_exe)
tests = sorted([ tests = sorted([
filename for filename in os.listdir(tests_path) filename for filename in os.listdir(tests_path)
@ -97,11 +97,12 @@ def integration_tests(deno_exe, test_filter = None):
print green_ok() print green_ok()
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--filter", help="Run specific tests") parser.add_argument("--filter", help="Run specific tests")
parser.add_argument("--release", help="Use release build of Deno", parser.add_argument(
action="store_true") "--release", help="Use release build of Deno", action="store_true")
parser.add_argument("--executable", help="Use external executable of Deno") parser.add_argument("--executable", help="Use external executable of Deno")
args = parser.parse_args() args = parser.parse_args()

View file

@ -10,15 +10,18 @@ from permission_prompt_test import tty_capture
IS_TTY_TEST_TS = "tests/is_tty.ts" IS_TTY_TEST_TS = "tests/is_tty.ts"
def is_tty_test(deno_exe): def is_tty_test(deno_exe):
cmd = [deno_exe, IS_TTY_TEST_TS] cmd = [deno_exe, IS_TTY_TEST_TS]
code, stdout, _ = tty_capture(cmd, b'') code, stdout, _ = tty_capture(cmd, b'')
assert code == 0 assert code == 0
assert str(stdin.isatty()).lower() in stdout assert str(stdin.isatty()).lower() in stdout
def main(): def main():
deno_exe = os.path.join(build_path(), "deno" + executable_suffix) deno_exe = os.path.join(build_path(), "deno" + executable_suffix)
is_tty_test(deno_exe) is_tty_test(deno_exe)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -15,8 +15,8 @@ tslint = os.path.join(third_party_path, "node_modules", "tslint", "bin",
os.chdir(root_path) os.chdir(root_path)
run([ run([
"python", cpplint, "--filter=-build/include_subdir", "--repository=libdeno", "python", cpplint, "--filter=-build/include_subdir",
"--extensions=cc,h", "--recursive", "libdeno" "--repository=libdeno", "--extensions=cc,h", "--recursive", "libdeno"
]) ])
run(["node", tslint, "-p", ".", "--exclude", "**/gen/**/*.ts"]) run(["node", tslint, "-p", ".", "--exclude", "**/gen/**/*.ts"])

View file

@ -1,10 +1,10 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { args, listen, env, exit, makeTempDirSync, readFile, run} from "deno"; import { args, listen, env, exit, makeTempDirSync, readFile, run } from "deno";
const name = args[1]; const name = args[1];
const test = { const test = {
needsRead: () => { needsRead: () => {
readFile("package.json") readFile("package.json");
}, },
needsWrite: () => { needsWrite: () => {
makeTempDirSync(); makeTempDirSync();

View file

@ -38,7 +38,6 @@ def test_no_color(deno_exe):
print green_ok() print green_ok()
def main(argv): def main(argv):
if len(argv) == 2: if len(argv) == 2:
build_dir = sys.argv[1] build_dir = sys.argv[1]

View file

@ -255,8 +255,7 @@ def download_clang_format():
# Download clang by calling the clang update script. # Download clang by calling the clang update script.
def download_clang(): def download_clang():
run(['python', tp('v8/tools/clang/scripts/update.py')], run(['python', tp('v8/tools/clang/scripts/update.py')], env=google_env())
env=google_env())
def maybe_download_sysroot(): def maybe_download_sysroot():

View file

@ -46,7 +46,8 @@ def unit_tests(deno_exe):
run_unit_test(deno_exe, "permR0W0N0E0U0") run_unit_test(deno_exe, "permR0W0N0E0U0")
run_unit_test(deno_exe, "permR1W0N0E0U0", ["--allow-read"]) run_unit_test(deno_exe, "permR1W0N0E0U0", ["--allow-read"])
run_unit_test(deno_exe, "permR0W1N0E0U0", ["--allow-write"]) run_unit_test(deno_exe, "permR0W1N0E0U0", ["--allow-write"])
run_unit_test(deno_exe, "permR1W1N0E0U0", ["--allow-read", "--allow-write"]) run_unit_test(deno_exe, "permR1W1N0E0U0",
["--allow-read", "--allow-write"])
run_unit_test(deno_exe, "permR1W0N1E0U0", ["--allow-read", "--allow-net"]) run_unit_test(deno_exe, "permR1W0N1E0U0", ["--allow-read", "--allow-net"])
run_unit_test(deno_exe, "permR0W0N0E1U0", ["--allow-env"]) run_unit_test(deno_exe, "permR0W0N0E1U0", ["--allow-env"])
run_unit_test(deno_exe, "permR0W0N0E0U1", ["--allow-run"]) run_unit_test(deno_exe, "permR0W0N0E0U1", ["--allow-run"])

View file

@ -383,6 +383,7 @@ def parse_wrk_output(output):
def platform(): def platform():
return {"linux2": "linux", "darwin": "mac", "win32": "win"}[sys.platform] return {"linux2": "linux", "darwin": "mac", "win32": "win"}[sys.platform]
def mkdtemp(): def mkdtemp():
# On Windows, set the base directory that mkdtemp() uses explicitly. If not, # 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 # it'll use the short (8.3) path to the temp dir, which triggers the error