Skip to content

Commit

Permalink
test: add tests for basic hir compiler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
junlarsen committed Feb 9, 2025
1 parent 9289ad0 commit 21dce77
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[alias]
xtask = "run --package eight-xtask --"
regtest = "run --package eight-regtest -- verify"
regtest = "run --package eight-regtest -- verify tests"

[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }
5 changes: 5 additions & 0 deletions tests/ui/hir/break-outside-loop.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

fn main() -> i32 {
break;
}
11 changes: 11 additions & 0 deletions tests/ui/hir/break-outside-loop.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::break_outside_loop

× break statement outside of loop
╭─[break-outside-loop.eight:4:3]
3fn main() -> i32 {
4break;
· ───┬──
· ╰── there is no enclosing loop
5 │ }
╰────

5 changes: 5 additions & 0 deletions tests/ui/hir/continue-outside-loop.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

fn test() -> bool {
continue;
}
11 changes: 11 additions & 0 deletions tests/ui/hir/continue-outside-loop.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::continue_outside_loop

× continue statement outside of loop
╭─[continue-outside-loop.eight:4:3]
3fn test() -> bool {
4continue;
· ────┬────
· ╰── there is no enclosing loop
5 │ }
╰────

5 changes: 5 additions & 0 deletions tests/ui/hir/invalid-reference.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

fn main() -> i32 {
return somebody_help_i_got_a_bad_reference;
}
11 changes: 11 additions & 0 deletions tests/ui/hir/invalid-reference.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::invalid_reference

× invalid reference to somebody_help_i_got_a_bad_reference
╭─[invalid-reference.eight:4:10]
3fn main() -> i32 {
4return somebody_help_i_got_a_bad_reference;
· ─────────────────┬─────────────────
· ╰── no value in scope named somebody_help_i_got_a_bad_reference
5 │ }
╰────

5 changes: 5 additions & 0 deletions tests/ui/hir/type-field-infinite-recursion.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

struct Foo {
bar: Foo,
}
11 changes: 11 additions & 0 deletions tests/ui/hir/type-field-infinite-recursion.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::infinitely_recursive_type

× type is recursive
╭─[type-field-infinite-recursion.eight:4:3]
3struct Foo {
4 │ bar: Foo,
· ────┬────
· ╰── type Foo has an infinite recursion in field bar
5 │ }
╰────

7 changes: 7 additions & 0 deletions tests/ui/hir/unknown-type.eight
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: not %eightc %s 2>&1 | %regtest test %s

intrinsic_fn get_id<T>() -> T;

fn main() {
let bananas: Banana = get_id();
}
11 changes: 11 additions & 0 deletions tests/ui/hir/unknown-type.eight.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Error: sema::unknown_type

× Banana does not name a known type
╭─[unknown-type.eight:6:16]
5fn main() {
6let bananas: Banana = get_id();
· ───┬──
· ╰── could not find type Banana
7 │ }
╰────

Empty file removed tools/eight-regtest/snapshot.rs
Empty file.
4 changes: 2 additions & 2 deletions tools/eight-regtest/src/bin/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ fn verify(args: CommandVerifyArgs) -> anyhow::Result<()> {
clearscreen::clear()?;
let base_path = get_base_path(&path);
let state = get_snapshot_state(&base_path)?;
let (previous, snapshot) = match &state {
let (previous, current) = match &state {
SnapshotState::Verified(s) | SnapshotState::Unverified(s) => ("", s.as_str()),
SnapshotState::PreviouslyRegressed(r, s) => (r.as_str(), s.as_str()),
SnapshotState::Fresh => unreachable!(
"should not be possible to have just-verified snapshot in verification step"
),
};

let (_, diff) = get_annotated_diff(previous, snapshot);
let (_, diff) = get_annotated_diff(current, previous);
println!(
"{} {}",
"Displaying diff for snapshot file".cyan(),
Expand Down

0 comments on commit 21dce77

Please sign in to comment.