diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/specs/lint/jsr_tag/__test__.jsonc | 14 | ||||
-rw-r--r-- | tests/specs/lint/jsr_tag/non_package.out | 1 | ||||
-rw-r--r-- | tests/specs/lint/jsr_tag/non_package/mod.ts | 3 | ||||
-rw-r--r-- | tests/specs/lint/jsr_tag/non_package/type.ts | 1 | ||||
-rw-r--r-- | tests/specs/lint/jsr_tag/package.out | 12 | ||||
-rw-r--r-- | tests/specs/lint/jsr_tag/package/deno.json | 5 | ||||
-rw-r--r-- | tests/specs/lint/jsr_tag/package/mod.ts | 3 | ||||
-rw-r--r-- | tests/specs/lint/jsr_tag/package/type.ts | 1 | ||||
-rw-r--r-- | tests/specs/mod.rs | 39 |
9 files changed, 67 insertions, 12 deletions
diff --git a/tests/specs/lint/jsr_tag/__test__.jsonc b/tests/specs/lint/jsr_tag/__test__.jsonc new file mode 100644 index 000000000..100dcbd13 --- /dev/null +++ b/tests/specs/lint/jsr_tag/__test__.jsonc @@ -0,0 +1,14 @@ +{ + // packages will be automatically entered into the "jsr" tag + "steps": [{ + "args": "lint", + "cwd": "./package", + "output": "package.out", + "exitCode": 1 + }, { + "args": "lint", + "cwd": "./non_package", + "output": "non_package.out", + "exitCode": 0 + }] +} diff --git a/tests/specs/lint/jsr_tag/non_package.out b/tests/specs/lint/jsr_tag/non_package.out new file mode 100644 index 000000000..158c556c2 --- /dev/null +++ b/tests/specs/lint/jsr_tag/non_package.out @@ -0,0 +1 @@ +Checked 2 files diff --git a/tests/specs/lint/jsr_tag/non_package/mod.ts b/tests/specs/lint/jsr_tag/non_package/mod.ts new file mode 100644 index 000000000..efb884a2c --- /dev/null +++ b/tests/specs/lint/jsr_tag/non_package/mod.ts @@ -0,0 +1,3 @@ +import { MyType } from "./type.ts"; + +export const myVar: MyType = "hello"; diff --git a/tests/specs/lint/jsr_tag/non_package/type.ts b/tests/specs/lint/jsr_tag/non_package/type.ts new file mode 100644 index 000000000..ed7545c16 --- /dev/null +++ b/tests/specs/lint/jsr_tag/non_package/type.ts @@ -0,0 +1 @@ +export type MyType = string; diff --git a/tests/specs/lint/jsr_tag/package.out b/tests/specs/lint/jsr_tag/package.out new file mode 100644 index 000000000..5169d9815 --- /dev/null +++ b/tests/specs/lint/jsr_tag/package.out @@ -0,0 +1,12 @@ +error[verbatim-module-syntax]: All import identifiers are used in types + --> [WILDCARD]mod.ts:1:1 + | +1 | import { MyType } from "./type.ts"; + | ^^^^^^ + = hint: Change `import` to `import type` and optionally add an explicit side effect import + + docs: https://lint.deno.land/rules/verbatim-module-syntax + + +Found 1 problem (1 fixable via --fix) +Checked 2 files diff --git a/tests/specs/lint/jsr_tag/package/deno.json b/tests/specs/lint/jsr_tag/package/deno.json new file mode 100644 index 000000000..8c1c8f8a4 --- /dev/null +++ b/tests/specs/lint/jsr_tag/package/deno.json @@ -0,0 +1,5 @@ +{ + "name": "@scope/package", + "version": "1.0.0", + "exports": "./mod.ts" +} diff --git a/tests/specs/lint/jsr_tag/package/mod.ts b/tests/specs/lint/jsr_tag/package/mod.ts new file mode 100644 index 000000000..efb884a2c --- /dev/null +++ b/tests/specs/lint/jsr_tag/package/mod.ts @@ -0,0 +1,3 @@ +import { MyType } from "./type.ts"; + +export const myVar: MyType = "hello"; diff --git a/tests/specs/lint/jsr_tag/package/type.ts b/tests/specs/lint/jsr_tag/package/type.ts new file mode 100644 index 000000000..ed7545c16 --- /dev/null +++ b/tests/specs/lint/jsr_tag/package/type.ts @@ -0,0 +1 @@ +export type MyType = string; diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs index feed09871..3eb8bb386 100644 --- a/tests/specs/mod.rs +++ b/tests/specs/mod.rs @@ -128,19 +128,22 @@ fn run_test(test: &Test, diagnostic_logger: Rc<RefCell<Vec<u8>>>) { context.deno_dir().path().remove_dir_all(); } - let expected_output = if step.output.ends_with(".out") { - let test_output_path = cwd.join(&step.output); - test_output_path.read_to_string() - } else { - step.output.clone() - }; let command = context.new_command().envs(&step.envs); let command = match &step.args { VecOrString::Vec(args) => command.args_vec(args), VecOrString::String(text) => command.args(text), }; + let command = match &step.cwd { + Some(cwd) => command.current_dir(cwd), + None => command, + }; let output = command.run(); - output.assert_matches_text(expected_output); + if step.output.ends_with(".out") { + let test_output_path = cwd.join(&step.output); + output.assert_matches_file(test_output_path); + } else { + output.assert_matches_text(&step.output); + } output.assert_exit_code(step.exit_code); } } @@ -194,6 +197,7 @@ struct StepMetaData { #[serde(default)] pub clean_deno_dir: bool, pub args: VecOrString, + pub cwd: Option<String>, #[serde(default)] pub envs: HashMap<String, String>, pub output: String, @@ -299,12 +303,23 @@ fn collect_tests() -> Vec<TestCategory> { } .with_context(|| format!("Failed to parse {}", metadata_path)) .unwrap(); + + let test_name = + format!("{}::{}", category.name, entry.file_name().to_string_lossy()); + + // only support characters that work with filtering with `cargo test` + if !test_name + .chars() + .all(|c| c.is_alphanumeric() || matches!(c, '_' | ':')) + { + panic!( + "Invalid test name (only supports alphanumeric and underscore): {}", + test_name + ); + } + category.tests.push(Test { - name: format!( - "{}::{}", - category.name, - entry.file_name().to_string_lossy() - ), + name: test_name, cwd: test_dir, metadata, }); |