aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/functions.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-03-31 13:16:08 -0600
committerMelody Horn <melody@boringcactus.com>2021-03-31 13:16:08 -0600
commit42bdec6488da15a12f2324526bf81abd389f2b4d (patch)
tree613e286384e485bb95a11e5b25a609e105f5d3d5 /src/makefile/functions.rs
parentdc02827184245392d3059bea150814d28d34a7fe (diff)
downloadmakers-42bdec6488da15a12f2324526bf81abd389f2b4d.tar.gz
makers-42bdec6488da15a12f2324526bf81abd389f2b4d.zip
fix the tests oops
Diffstat (limited to 'src/makefile/functions.rs')
-rw-r--r--src/makefile/functions.rs41
1 files changed, 26 insertions, 15 deletions
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<String> {
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")
],
&macros,
- ),
+ )?,
"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")
],
&macros,
- ),
+ )?,
"b a"
);
+ Ok(())
}
}