Skip to content

Commit

Permalink
Add ctfails tests for expected codegen failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratmice committed Aug 30, 2023
1 parent e66c69c commit ba460a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lrpar/cttests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ use cfgrammar::yacc::{YaccKind, YaccOriginalActionKind};
use glob::glob;
use lrlex::{CTLexerBuilder, DefaultLexerTypes};
use lrpar::CTParserBuilder;
use std::{env, fs, path::PathBuf};
use std::{
env, fs,
path::{Path, PathBuf},
};
use yaml_rust::YamlLoader;

fn run_test_path(path: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
fn run_test_path<P: AsRef<Path>>(path: P) -> Result<(), Box<dyn std::error::Error>> {
let out_dir = env::var("OUT_DIR").unwrap();
let path = path.as_ref();
if path.is_file() {
println!("cargo:rerun-if-changed={}", path.display());
// Parse test file
Expand Down Expand Up @@ -147,6 +151,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for entry in glob("src/*.test")? {
run_test_path(entry.unwrap())?;
}
for entry in glob("src/ctfails/*.test")? {
let path = entry.unwrap();
let result =
std::panic::catch_unwind(|| std::panic::AssertUnwindSafe(run_test_path(&path).is_ok()));
if !result.is_err() {
panic!(
"ctfails/{}: succeded unexpectedly with result {:?}",
path.display(),
result
);
}
}
Ok(())
}

Expand Down
10 changes: 10 additions & 0 deletions lrpar/cttests/src/ctfails/missing.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Test missing terms in lexer and parser
yacckind: Original(YaccOriginalActionKind::NoAction)
lex_flags: [ '!allow_missing_terms_in_lexer', '!allow_missing_tokens_in_parser' ]
grammar: |
%%
S: 'B';

lexer: |
%%
A "A"

0 comments on commit ba460a6

Please sign in to comment.