diff options
-rw-r--r-- | js/main.ts | 12 | ||||
-rw-r--r-- | src/flags.rs | 24 | ||||
-rw-r--r-- | src/isolate.rs | 9 | ||||
-rw-r--r-- | src/msg.fbs | 1 | ||||
-rw-r--r-- | src/ops.rs | 7 | ||||
-rwxr-xr-x | tools/unit_tests.py | 18 |
6 files changed, 58 insertions, 13 deletions
diff --git a/js/main.ts b/js/main.ts index 826d3e811..24418b53e 100644 --- a/js/main.ts +++ b/js/main.ts @@ -48,6 +48,14 @@ export default function denoMain() { setLogDebug(startResMsg.debugFlag()); + // handle `--types` + if (startResMsg.typesFlag()) { + const defaultLibFileName = compiler.getDefaultLibFileName(); + const defaultLibModule = compiler.resolveModule(defaultLibFileName, ""); + console.log(defaultLibModule.sourceCode); + os.exit(0); + } + const cwd = startResMsg.cwd(); log("cwd", cwd); @@ -64,8 +72,8 @@ export default function denoMain() { os.exit(1); } - const printDeps = startResMsg.depsFlag(); - if (printDeps) { + // handle `--deps` + if (startResMsg.depsFlag()) { for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) { console.log(dep); } diff --git a/src/flags.rs b/src/flags.rs index 82b7f528d..e4e3c28df 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -26,6 +26,7 @@ pub struct DenoFlags { pub allow_net: bool, pub allow_env: bool, pub deps_flag: bool, + pub types_flag: bool, } pub fn process(flags: &DenoFlags) { @@ -58,7 +59,8 @@ pub fn print_usage() { -D or --log-debug Log debug output. -h or --help Print this message. --v8-options Print V8 command line options. ---deps Print module dependencies." +--deps Print module dependencies. +--types Print runtime TypeScript declarations." ); } @@ -82,6 +84,7 @@ pub fn set_flags(args: Vec<String>) -> (DenoFlags, Vec<String>) { "--allow-net" => flags.allow_net = true, "--allow-env" => flags.allow_env = true, "--deps" => flags.deps_flag = true, + "--types" => flags.types_flag = true, "--" => break, _ => unimplemented!(), } @@ -165,6 +168,19 @@ fn test_set_flags_4() { ); } +#[test] +fn test_set_flags_5() { + let (flags, rest) = set_flags(svec!["deno", "--types"]); + assert_eq!(rest, svec!["deno"]); + assert_eq!( + flags, + DenoFlags { + types_flag: true, + ..DenoFlags::default() + } + ) +} + // Returns args passed to V8, followed by args passed to JS fn v8_set_flags_preprocess(args: Vec<String>) -> (Vec<String>, Vec<String>) { let mut rest = vec![]; @@ -179,7 +195,8 @@ fn v8_set_flags_preprocess(args: Vec<String>) -> (Vec<String>, Vec<String>) { } true - }).collect(); + }) + .collect(); // Replace args being sent to V8 for idx in 0..args.len() { @@ -248,6 +265,7 @@ pub fn v8_set_flags(args: Vec<String>) -> Vec<String> { let cstr = CStr::from_ptr(*ptr as *const i8); let slice = cstr.to_str().unwrap(); slice.to_string() - }).chain(rest.into_iter()) + }) + .chain(rest.into_iter()) .collect() } diff --git a/src/isolate.rs b/src/isolate.rs index e24471356..40dff5ed2 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -348,7 +348,8 @@ mod tests { throw Error("assert error"); } "#, - ).expect("execute error"); + ) + .expect("execute error"); isolate.event_loop(); }); } @@ -392,7 +393,8 @@ mod tests { const data = new Uint8Array([42, 43, 44, 45, 46]); libdeno.send(control, data); "#, - ).expect("execute error"); + ) + .expect("execute error"); isolate.event_loop(); let metrics = isolate.state.metrics.lock().unwrap(); assert_eq!(metrics.ops_dispatched, 1); @@ -427,7 +429,8 @@ mod tests { let r = libdeno.send(control, data); if (r != null) throw Error("expected null"); "#, - ).expect("execute error"); + ) + .expect("execute error"); // Make sure relevant metrics are updated before task is executed. { diff --git a/src/msg.fbs b/src/msg.fbs index 40179fc14..43fde4d68 100644 --- a/src/msg.fbs +++ b/src/msg.fbs @@ -111,6 +111,7 @@ table StartRes { debug_flag: bool; deps_flag: bool; recompile_flag: bool; + types_flag: bool; } table CodeFetch { diff --git a/src/ops.rs b/src/ops.rs index c32f53634..a58532baf 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -185,6 +185,7 @@ fn op_start( argv: Some(argv_off), debug_flag: state.flags.log_debug, recompile_flag: state.flags.recompile, + types_flag: state.flags.types_flag, ..Default::default() }, ); @@ -342,7 +343,8 @@ fn op_env( ..Default::default() }, ) - }).collect(); + }) + .collect(); let tables = builder.create_vector(&vars); let inner = msg::EnvironRes::create( builder, @@ -891,7 +893,8 @@ fn op_read_dir( ..Default::default() }, ) - }).collect(); + }) + .collect(); let entries = builder.create_vector(&entries); let inner = msg::ReadDirRes::create( diff --git a/tools/unit_tests.py b/tools/unit_tests.py index b9be48436..14f1d18b7 100755 --- a/tools/unit_tests.py +++ b/tools/unit_tests.py @@ -4,9 +4,7 @@ import sys import subprocess import re - -def run_unit_test(deno_exe, permStr, flags=[]): - cmd = [deno_exe, "--reload", "js/unit_tests.ts", permStr] + flags +def run_unit_test2(cmd): process = subprocess.Popen( cmd, bufsize=1, @@ -28,6 +26,10 @@ def run_unit_test(deno_exe, permStr, flags=[]): if errcode != 0: sys.exit(errcode) +def run_unit_test(deno_exe, permStr, flags=[]): + cmd = [deno_exe, "--reload", "js/unit_tests.ts", permStr] + flags + run_unit_test2(cmd) + # We want to test many ops in deno which have different behavior depending on # the permissions set. These tests can specify which permissions they expect, @@ -43,6 +45,16 @@ def unit_tests(deno_exe): # TODO We might accidentally miss some. We should be smarter about which we # run. Maybe we can use the "filtered out" number to check this. + # These are not strictly unit tests for Deno, but for ts_library_builder. + # They run under Node, but use the same //js/testing/ library. + run_unit_test2([ + "node", + "./node_modules/.bin/ts-node", + "--project", + "tools/ts_library_builder/tsconfig.json", + "tools/ts_library_builder/test.ts" + ]) + if __name__ == '__main__': if len(sys.argv) < 2: |