Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Support more directives in file analyzer testing system #1069

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 7 additions & 31 deletions crates/stc_ts_file_analyzer/tests/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rnode::{NodeIdGenerator, RNode, VisitWith};
use stc_testing::logger;
use stc_ts_ast_rnode::RModule;
use stc_ts_builtin_types::Lib;
use stc_ts_env::{Env, ModuleConfig, Rule};
use stc_ts_env::Env;
use stc_ts_errors::{debug::debugger::Debugger, ErrorKind};
use stc_ts_file_analyzer::{
analyzer::{Analyzer, NoopLoader},
Expand Down Expand Up @@ -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<Lib>) -> Env {
let case = parse_conformance_test(path).unwrap().into_iter().next().unwrap();
libs.extend(&case.libs);
let ls = &[
"es2022.full",
"es2021.full",
Expand All @@ -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<StcError> {
Expand All @@ -78,7 +71,7 @@ fn validate(input: &Path) -> Vec<StcError> {

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()));
Expand Down Expand Up @@ -240,8 +233,6 @@ fn run_test(file_name: PathBuf, want_error: bool, disable_logging: bool) -> Opti
let filename = file_name.display().to_string();
println!("{}", filename);

let case = parse_conformance_test(&file_name).unwrap().into_iter().next().unwrap();

let result = testing::Tester::new()
.print_errors(|cm, handler| -> Result<(), _> {
let _tracing = if disable_logging {
Expand All @@ -252,22 +243,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()));
Expand Down
5 changes: 5 additions & 0 deletions crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @strictNullChecks: true
// @declaration: true

declare let a : string;
a = "a" as string | undefined;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"file": "tests/tsc/rule/strictNullCheck.ts",
"line": 5,
"col": 1,
"code": 2322
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"file": "tests/tsc/types/intersection/withUnionConstraint/1.ts",
"line": 4,
"col": 9,
"code": 2322
}
]
1 change: 1 addition & 0 deletions crates/stc_ts_type_checker/tests/tsc-stats.rust-debug
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Stats {
required_error: 3502,
matched_error: 6533,
extra_error: 764,
panic: 73,
}
Loading