aboutsummaryrefslogtreecommitdiffstats
path: root/sylt_macro
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-03-05 19:47:00 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-03-05 19:47:00 +0100
commitb1fab16befb78232d7a913f58beef639c5891e26 (patch)
tree3a8596bca862ecee3d464aa933bd6411d4c442a8 /sylt_macro
parent0b15a38e324c3940318df462812c42f74a544267 (diff)
downloadsylt-b1fab16befb78232d7a913f58beef639c5891e26.tar.gz
set no_print in tests
Diffstat (limited to 'sylt_macro')
-rw-r--r--sylt_macro/src/lib.rs44
1 files changed, 37 insertions, 7 deletions
diff --git a/sylt_macro/src/lib.rs b/sylt_macro/src/lib.rs
index 96f7112..95b79c6 100644
--- a/sylt_macro/src/lib.rs
+++ b/sylt_macro/src/lib.rs
@@ -160,13 +160,41 @@ pub fn link(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
proc_macro::TokenStream::from(tokens)
}
-fn parse_test(contents: String) -> Option<String> {
+struct TestSettings {
+ errors: Option<String>,
+ print: bool,
+}
+
+impl Default for TestSettings {
+ fn default() -> Self {
+ Self {
+ errors: None,
+ print: true,
+ }
+ }
+}
+
+fn parse_test_settings(contents: String) -> TestSettings {
+ let mut settings = TestSettings::default();
+
for line in contents.split("\n") {
if line.starts_with("// errors: ") {
- return Some(line.strip_prefix("// errors: ").unwrap().to_string());
+ settings.errors = Some(line.strip_prefix("// errors: ").unwrap().to_string());
+ } else if line.starts_with("// flags: ") {
+ for flag in line.split(" ").skip(2) {
+ match flag {
+ "no_print" => {
+ settings.print = false;
+ }
+ _ => {
+ panic!("Unknown test flag '{}'", flag);
+ }
+ }
+ }
}
}
- None
+
+ settings
}
fn find_test_paths(directory: &Path) -> proc_macro2::TokenStream {
@@ -188,14 +216,16 @@ fn find_test_paths(directory: &Path) -> proc_macro2::TokenStream {
let path_string = path.to_str().unwrap();
let test_name = format_ident!("file_{}", file_name.replace(".sy", ""));
- let tokens = if let Some(wanted_err) = parse_test(std::fs::read_to_string(path.clone()).unwrap()) {
- let wanted_err: proc_macro2::TokenStream = wanted_err.parse().unwrap();
+ let settings = parse_test_settings(std::fs::read_to_string(path.clone()).unwrap());
+ let print = settings.print;
+ let tokens = if let Some(wanted_errs) = settings.errors {
+ let wanted_errs: proc_macro2::TokenStream = wanted_errs.parse().unwrap();
quote! {
- test_file!(#test_name, #path_string, #wanted_err);
+ test_file!(#test_name, #path_string, #print, #wanted_errs);
}
} else {
quote! {
- test_file!(#test_name, #path_string);
+ test_file!(#test_name, #path_string, #print);
}
};