From 42bdec6488da15a12f2324526bf81abd389f2b4d Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 31 Mar 2021 13:16:08 -0600 Subject: fix the tests oops --- src/makefile/functions.rs | 41 ++++++++++++++++++++++++++--------------- src/makefile/mod.rs | 16 ++++++++++------ src/makefile/pattern.rs | 9 ++++++--- src/makefile/token.rs | 27 +++++++++++++++++---------- 4 files changed, 59 insertions(+), 34 deletions(-) (limited to 'src/makefile') diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index 8087a94..b4687c3 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -248,60 +248,68 @@ mod test { use crate::makefile::r#macro::{MacroSet, MacroSource}; + type R = anyhow::Result<()>; + fn call(name: &str, args: &[TokenString], macros: &MacroSet) -> anyhow::Result { super::expand_call(name, args, macros) } macro_rules! call { ($func:literal $($arg:literal),+) => { - call($func, &[$(TokenString::text($arg)),+], &MacroSet::new()) + call($func, &[$(TokenString::text($arg)),+], &MacroSet::new())? }; ($func:ident $($arg:literal),+) => { - call(stringify!($func), &[$(TokenString::text($arg)),+], &MacroSet::new()) + call(stringify!($func), &[$(TokenString::text($arg)),+], &MacroSet::new())? }; } #[test] - fn filter() { + fn filter() -> R { let result = call!(filter "word", "this contains a word inside it"); assert_eq!(result, "word"); let result = call!(filter "%.c %.s", "foo.c bar.c baz.s ugh.h"); assert_eq!(result, "foo.c bar.c baz.s"); + Ok(()) } #[test] - fn filter_out() { + fn filter_out() -> R { let result = call!("filter-out" "main1.o main2.o", "main1.o foo.o main2.o bar.o"); assert_eq!(result, "foo.o bar.o"); + Ok(()) } #[test] - fn sort() { + fn sort() -> R { let result = call!(sort "foo bar lose foo"); assert_eq!(result, "bar foo lose"); + Ok(()) } #[test] - fn notdir() { + fn notdir() -> R { let result = call!(notdir "src/foo.c hacks"); assert_eq!(result, "foo.c hacks"); + Ok(()) } #[test] - fn basename() { + fn basename() -> R { let result = call!(basename "src/foo.c src-1.0/bar hacks"); assert_eq!(result, "src/foo src-1.0/bar hacks"); + Ok(()) } #[test] - fn addprefix() { + fn addprefix() -> R { let result = call!(addprefix "src/", "foo bar"); assert_eq!(result, "src/foo src/bar"); + Ok(()) } #[test] - fn wildcard() { + fn wildcard() -> R { use std::env::{set_current_dir, set_var}; use std::fs::write; use std::path::MAIN_SEPARATOR; @@ -317,19 +325,20 @@ mod test { set_current_dir(tempdir.path()).unwrap(); set_var("HOME", tempdir.path().to_str().unwrap()); let sort = |x: String| call("sort", &[TokenString::text(&x)], &MacroSet::new()); - assert_eq!(sort(call!(wildcard "*.c")), "acab.c foo.c"); + assert_eq!(sort(call!(wildcard "*.c"))?, "acab.c foo.c"); assert_eq!( - sort(call!(wildcard "~/ba?.*")), + sort(call!(wildcard "~/ba?.*"))?, format!( "{0}{1}bar.h {0}{1}baz.txt", tempdir.path().to_str().unwrap(), MAIN_SEPARATOR ) ); + Ok(()) } #[test] - fn foreach() { + fn foreach() -> R { let mut macros = MacroSet::new(); macros.set( "test".to_string(), @@ -345,13 +354,14 @@ mod test { TokenString::r#macro("test") ], ¯os, - ), + )?, "worked for a. worked for b. worked for c. worked for d." ); + Ok(()) } #[test] - fn call_test() { + fn call_test() -> R { let mut macros = MacroSet::new(); macros.set( "reverse".to_string(), @@ -367,8 +377,9 @@ mod test { TokenString::text("b") ], ¯os, - ), + )?, "b a" ); + Ok(()) } } diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index c48c030..582c62d 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -693,6 +693,8 @@ mod test { use super::*; + type R = anyhow::Result<()>; + fn empty_makefile(args: &Args) -> Makefile { Makefile { inference_rules: vec![], @@ -704,7 +706,7 @@ mod test { } #[test] - fn basic_conditionals() { + fn basic_conditionals() -> R { let file = " ifeq (1,1) worked = yes @@ -714,16 +716,17 @@ endif "; let args = Args::empty(); let mut makefile = empty_makefile(&args); - makefile.and_read(Cursor::new(file)); + makefile.and_read(Cursor::new(file))?; assert_eq!( - makefile.expand_macros(&TokenString::r#macro("worked"), None), + makefile.expand_macros(&TokenString::r#macro("worked"), None)?, "yes" ); + Ok(()) } #[test] #[ignore = "I still haven't implemented `eval` or `define` or %-based macro substitution."] - fn eval() { + fn eval() -> R { // This, for the record, is a terrible misfeature. // If you need this, you probably shouldn't be using Make. // But a lot of people are using this and still use Make anyway, so here we go, @@ -759,7 +762,8 @@ clean: let args = Args::empty(); let mut makefile = empty_makefile(&args); - makefile.and_read(Cursor::new(file)); - assert!(makefile.targets.borrow().contains_key("server")) + makefile.and_read(Cursor::new(file))?; + assert!(makefile.targets.borrow().contains_key("server")); + Ok(()) } } diff --git a/src/makefile/pattern.rs b/src/makefile/pattern.rs index 2d5f46c..fbd89a5 100644 --- a/src/makefile/pattern.rs +++ b/src/makefile/pattern.rs @@ -32,12 +32,15 @@ pub(crate) fn r#match<'a>(pattern: &str, text: &'a str) -> anyhow::Result