-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #518 from shiika-lang/error-message-tests
Add tests for erroneous Shiika programs
- Loading branch information
Showing
14 changed files
with
402 additions
and
35 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Tests | ||
|
||
## `tests/sk` | ||
|
||
This directory contains various Shiika programs and run by `tests/integration_test.rs`. | ||
|
||
### Conventions | ||
|
||
.sk in this directory | ||
|
||
- must ends with `puts "ok"` | ||
- must not print anything other if succeed | ||
- should print error message if failed | ||
|
||
## `tests/erroneous` | ||
|
||
This directory contains various Shiika programs which is expected to cause compilation error. | ||
The expected output is stored in `snapshots` directory with the [insta crate](https://insta.rs/docs/). | ||
|
||
However this does not mean current error messages are considered perfect; PRs to improve them are welcome. | ||
|
||
Rather than that, erroneous tests are for: | ||
|
||
- assuring the type checker detects various type errors | ||
- assuring the compiler does not crash with an erroneous program | ||
- investigating the impact of a modification to the type checker | ||
|
||
### How to add new .sk to `tests/erroneous` | ||
|
||
prerequisites: `cargo install cargo-insta` | ||
|
||
1. Create .sk | ||
2. `cargo test test_erroneous` (this will create `tests/snapshots/*.snap.new`) | ||
3. `cargo insta review` and accept the snapshot (this will rename `.snap.new` to `.snap`) | ||
4. Commit `.snap` to git | ||
|
||
### How to fix CI fail after changing error message | ||
|
||
TBA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use anyhow::Result; | ||
use concolor; | ||
use insta::{assert_snapshot, glob}; | ||
use shiika::runner; | ||
use std::path::Path; | ||
|
||
#[test] | ||
fn test_erroneous() -> Result<()> { | ||
concolor::set(concolor::ColorChoice::Never); | ||
let base = Path::new(".").canonicalize()?; | ||
glob!("erroneous/**/*.sk", |sk_path_| { | ||
// Make the path relative to the project root so that the resulting .snap will be | ||
// identical on my machine and in the CI environment. | ||
let sk_path = sk_path_.strip_prefix(&base).unwrap(); | ||
let compiler_output = match runner::compile(sk_path) { | ||
Ok(_) => "".to_string(), | ||
Err(comp_err) => comp_err.to_string(), | ||
}; | ||
assert_snapshot!(compiler_output); | ||
}); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class A : XXX | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts 123 |
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
tests/snapshots/erroneous__erroneous@class_definition__no_class_name.sk.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
source: tests/erroneous.rs | ||
expression: compiler_output | ||
input_file: tests/erroneous/class_definition/no_class_name.sk | ||
--- | ||
Error: class name must start with A-Z but got Separator | ||
╭─[tests/erroneous/class_definition/no_class_name.sk:1:6] | ||
│ | ||
1 │ class | ||
│ ─ | ||
│ | ||
───╯ | ||
) |
13 changes: 13 additions & 0 deletions
13
tests/snapshots/erroneous__erroneous@class_definition__unknown_superclass.sk.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
source: tests/erroneous.rs | ||
expression: compiler_output | ||
input_file: tests/erroneous/class_definition/unknown_superclass.sk | ||
--- | ||
Error: unknown type XXX in Namespace([]) | ||
╭─[tests/erroneous/class_definition/unknown_superclass.sk:1:11] | ||
│ | ||
1 │ class A : XXX | ||
│ ─┬─ | ||
│ ╰─── unknown type | ||
───╯ | ||
|
13 changes: 13 additions & 0 deletions
13
tests/snapshots/erroneous__erroneous@method_call__invalid_type.sk.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
source: tests/erroneous.rs | ||
expression: compiler_output | ||
input_file: tests/erroneous/method_call/invalid_type.sk | ||
--- | ||
Error: the argument `str' of `Object#puts' should be String but got Int | ||
╭─[tests/erroneous/method_call/invalid_type.sk:1:6] | ||
│ | ||
1 │ puts 123 | ||
│ ─┬─ | ||
│ ╰─── Int | ||
───╯ | ||
|