Skip to content

Commit 7a5bf92

Browse files
committed
Rewrite inline parser test infra to generated proper rust test cases
1 parent ef462ca commit 7a5bf92

File tree

503 files changed

+955
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

503 files changed

+955
-163
lines changed

crates/parser/src/grammar/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ fn macro_def(p: &mut Parser<'_>, m: Marker) {
388388
m.complete(p, MACRO_DEF);
389389
}
390390

391-
// test fn
391+
// test fn_
392392
// fn foo() {}
393393
fn fn_(p: &mut Parser<'_>, m: Marker) {
394394
p.bump(T![fn]);

crates/parser/src/grammar/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn array_or_slice_type(p: &mut Parser<'_>) {
169169
m.complete(p, kind);
170170
}
171171

172-
// test reference_type;
172+
// test reference_type
173173
// type A = &();
174174
// type B = &'static ();
175175
// type C = &mut ();

crates/parser/src/tests.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use expect_test::expect_file;
1111

1212
use crate::{Edition, LexedStr, TopEntryPoint};
1313

14+
#[path = "../test_data/generated/runner.rs"]
15+
mod runner;
16+
1417
#[test]
1518
fn lex_ok() {
1619
for case in TestCase::list("lexer/ok") {
@@ -54,16 +57,6 @@ fn parse_ok() {
5457
}
5558
}
5659

57-
#[test]
58-
fn parse_inline_ok() {
59-
for case in TestCase::list("parser/inline/ok") {
60-
let _guard = stdx::panic_context::enter(format!("{:?}", case.rs));
61-
let (actual, errors) = parse(TopEntryPoint::SourceFile, &case.text);
62-
assert!(!errors, "errors in an OK file {}:\n{actual}", case.rs.display());
63-
expect_file![case.rast].assert_eq(&actual);
64-
}
65-
}
66-
6760
#[test]
6861
fn parse_err() {
6962
for case in TestCase::list("parser/err") {
@@ -74,16 +67,6 @@ fn parse_err() {
7467
}
7568
}
7669

77-
#[test]
78-
fn parse_inline_err() {
79-
for case in TestCase::list("parser/inline/err") {
80-
let _guard = stdx::panic_context::enter(format!("{:?}", case.rs));
81-
let (actual, errors) = parse(TopEntryPoint::SourceFile, &case.text);
82-
assert!(errors, "no errors in an ERR file {}:\n{actual}", case.rs.display());
83-
expect_file![case.rast].assert_eq(&actual)
84-
}
85-
}
86-
8770
fn parse(entry: TopEntryPoint, text: &str) -> (String, bool) {
8871
let lexed = LexedStr::new(Edition::CURRENT, text);
8972
let input = lexed.to_input();
@@ -167,3 +150,27 @@ impl TestCase {
167150
res
168151
}
169152
}
153+
154+
#[track_caller]
155+
fn run_and_expect_no_errors(path: &str) {
156+
let path = PathBuf::from(path);
157+
let text = std::fs::read_to_string(&path).unwrap();
158+
let (actual, errors) = parse(TopEntryPoint::SourceFile, &text);
159+
assert!(!errors, "errors in an OK file {}:\n{actual}", path.display());
160+
let mut p = PathBuf::from("..");
161+
p.push(path);
162+
p.set_extension("rast");
163+
expect_file![p].assert_eq(&actual)
164+
}
165+
166+
#[track_caller]
167+
fn run_and_expect_errors(path: &str) {
168+
let path = PathBuf::from(path);
169+
let text = std::fs::read_to_string(&path).unwrap();
170+
let (actual, errors) = parse(TopEntryPoint::SourceFile, &text);
171+
assert!(errors, "no errors in an ERR file {}:\n{actual}", path.display());
172+
let mut p = PathBuf::from("..");
173+
p.push(path);
174+
p.set_extension("rast");
175+
expect_file![p].assert_eq(&actual)
176+
}

0 commit comments

Comments
 (0)