From ba460a64350439b36bc4f67beaf776acd81025bc Mon Sep 17 00:00:00 2001 From: matt rice Date: Tue, 29 Aug 2023 22:41:34 -0700 Subject: [PATCH] Add ctfails tests for expected codegen failures. --- lrpar/cttests/build.rs | 20 ++++++++++++++++++-- lrpar/cttests/src/ctfails/missing.test | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 lrpar/cttests/src/ctfails/missing.test diff --git a/lrpar/cttests/build.rs b/lrpar/cttests/build.rs index fdf73c906..2579203d9 100644 --- a/lrpar/cttests/build.rs +++ b/lrpar/cttests/build.rs @@ -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> { +fn run_test_path>(path: P) -> Result<(), Box> { 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 @@ -147,6 +151,18 @@ fn main() -> Result<(), Box> { 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(()) } diff --git a/lrpar/cttests/src/ctfails/missing.test b/lrpar/cttests/src/ctfails/missing.test new file mode 100644 index 000000000..0105becad --- /dev/null +++ b/lrpar/cttests/src/ctfails/missing.test @@ -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"