From 965344310f6ce14286d6a57ab747bacfcee09bd7 Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Fri, 18 Aug 2023 01:44:45 +0900 Subject: [PATCH] fix: a lot of test rule is not work --- crates/stc_ts_file_analyzer/tests/base.rs | 34 ++++--------------- .../tests/tsc/rule/strictNullCheck.ts | 5 +++ .../tsc/rule/strictNullCheck.tsc-errors.json | 8 +++++ .../tests/tsc-stats.rust-debug | 1 + 4 files changed, 20 insertions(+), 28 deletions(-) create mode 100644 crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.ts create mode 100644 crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.tsc-errors.json diff --git a/crates/stc_ts_file_analyzer/tests/base.rs b/crates/stc_ts_file_analyzer/tests/base.rs index 05da201bdd..28f55474ee 100644 --- a/crates/stc_ts_file_analyzer/tests/base.rs +++ b/crates/stc_ts_file_analyzer/tests/base.rs @@ -41,8 +41,9 @@ struct StcError { code: usize, } -fn get_env() -> Env { - let mut libs = vec![]; +fn get_env_from_path(path: &Path, mut libs: Vec) -> Env { + let case = parse_conformance_test(path).unwrap().into_iter().next().unwrap(); + libs.extend(&case.libs); let ls = &[ "es2022.full", "es2021.full", @@ -59,15 +60,7 @@ fn get_env() -> Env { libs.sort(); libs.dedup(); - Env::simple( - Rule { - strict_function_types: true, - ..Default::default() - }, - EsVersion::latest(), - ModuleConfig::None, - &libs, - ) + Env::simple(case.rule, case.target, case.module_config, &libs) } fn validate(input: &Path) -> Vec { @@ -78,7 +71,7 @@ fn validate(input: &Path) -> Vec { let fm = cm.load_file(input).unwrap(); - let env = get_env(); + let env = get_env_from_path(input, vec![]); let generator = module_id::ModuleIdGenerator::default(); let path = Arc::new(FileName::Real(input.to_path_buf())); @@ -252,22 +245,7 @@ fn run_test(file_name: PathBuf, want_error: bool, disable_logging: bool) -> Opti let handler = Arc::new(handler); let fm = cm.load_file(&file_name).unwrap(); - let mut libs = vec![]; - let ls = &[ - "es2020.full", - "es2019.full", - "es2018.full", - "es2017.full", - "es2016.full", - "es2015.full", - ]; - for s in ls { - libs.extend(Lib::load(s)) - } - libs.sort(); - libs.dedup(); - - let env = Env::simple(case.rule, case.target, case.module_config, &libs); + let env = get_env_from_path(&file_name, vec![]); let stable_env = env.shared().clone(); let generator = module_id::ModuleIdGenerator::default(); let path = Arc::new(FileName::Real(file_name.clone())); diff --git a/crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.ts b/crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.ts new file mode 100644 index 0000000000..ca1da46a9b --- /dev/null +++ b/crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.ts @@ -0,0 +1,5 @@ +// @strictNullChecks: true +// @declaration: true + +declare let a : string; +a = "a" as string | undefined; \ No newline at end of file diff --git a/crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.tsc-errors.json b/crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.tsc-errors.json new file mode 100644 index 0000000000..86cc3b9c18 --- /dev/null +++ b/crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.tsc-errors.json @@ -0,0 +1,8 @@ +[ + { + "file": "tests/tsc/rule/strictNullCheck.ts", + "line": 5, + "col": 1, + "code": 2322 + } +] \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug index 9a3b700764..02553a0cb6 100644 --- a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug @@ -2,4 +2,5 @@ Stats { required_error: 3502, matched_error: 6533, extra_error: 764, + panic: 73, } \ No newline at end of file