From 7ef5d27ea0088ba1b163168f8e7478288f0c2004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sun, 25 Oct 2020 14:06:46 +0100 Subject: [PATCH] Add abort_on_errors option Given syntex_syntax2 is a quite old parser, it doesn't support more recent syntax (especially macro expansions). This means API symbols created by macros using new features will not be tested. This allows a user to set abort_on_errors, and ctest will fail if the crate to be tested can't be parsed. --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4f7b78a..4543d98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,6 +110,7 @@ pub struct TestGenerator { fn_cname: Box) -> String>, const_cname: Box String>, rust_version: rustc_version::Version, + abort_on_errors: bool, } struct TyFinder { @@ -174,6 +175,7 @@ impl TestGenerator { }), const_cname: Box::new(std::string::ToString::to_string), rust_version: rustc_version::version().unwrap(), + abort_on_errors: false, } } @@ -778,6 +780,15 @@ impl TestGenerator { self } + /// Fail if parsing / macro expansion had errors + /// + /// Without this macro expansion errors are ignore (and the macro invocation is + /// treated like it didn't exist). + pub fn abort_on_errors(&mut self) -> &mut Self { + self.abort_on_errors = true; + self + } + /// Generate all tests. /// /// This function is first given the path to the `*-sys` crate which is @@ -1034,6 +1045,10 @@ impl TestGenerator { visit::walk_crate(&mut gen, &krate); gen.emit_run_all(); + if self.abort_on_errors { + sess.span_diagnostic.abort_if_errors(); + } + out_file } }