aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentdc02827184245392d3059bea150814d28d34a7fe (diff)
downloadmakers-42bdec6488da15a12f2324526bf81abd389f2b4d.tar.gz
makers-42bdec6488da15a12f2324526bf81abd389f2b4d.zip
fix the tests oops
Diffstat (limited to 'src')
-rw-r--r--src/makefile/functions.rs41
-rw-r--r--src/makefile/mod.rs16
-rw-r--r--src/makefile/pattern.rs9
-rw-r--r--src/makefile/token.rs27
4 files changed, 59 insertions, 34 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(())
}
}
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<Option
mod test {
use super::*;
+ type R = anyhow::Result<()>;
+
#[test]
- fn pattern_backslashes() {
- let test_case = compile_pattern(r"the\%weird\\%pattern\\");
+ fn pattern_backslashes() -> R {
+ let test_case = compile_pattern(r"the\%weird\\%pattern\\")?;
assert_eq!(test_case.to_string(), r"the%weird\\(\w*)pattern\\\\");
- let hell = compile_pattern(r"\\\\%");
+ let hell = compile_pattern(r"\\\\%")?;
assert_eq!(hell.to_string(), r"\\\\\\(\w*)");
+ Ok(())
}
}
diff --git a/src/makefile/token.rs b/src/makefile/token.rs
index 22ef24a..508a779 100644
--- a/src/makefile/token.rs
+++ b/src/makefile/token.rs
@@ -271,6 +271,8 @@ impl FromStr for TokenString {
mod test {
use super::{tokenize, Token, TokenString};
+ type R = anyhow::Result<()>;
+
impl From<Vec<Token>> for TokenString {
fn from(x: Vec<Token>) -> Self {
TokenString(x)
@@ -300,16 +302,17 @@ mod test {
}
#[test]
- fn no_macros() {
+ fn no_macros() -> R {
let text = "This is an example sentence! There aren't macros in it at all!";
- let tokens = tokenize(text);
+ let tokens = tokenize(text)?;
assert_eq!(tokens, TokenString(vec![token_text(text)]));
+ Ok(())
}
#[test]
- fn no_replacement() {
+ fn no_replacement() -> R {
let text = "This is a $Q sentence! There are $(BORING) macros in it at ${YEET}!";
- let tokens = tokenize(text);
+ let tokens = tokenize(text)?;
assert_eq!(
tokens,
TokenString(vec![
@@ -322,12 +325,13 @@ mod test {
token_text("!"),
])
);
+ Ok(())
}
#[test]
- fn escaped() {
+ fn escaped() -> R {
let text = "This costs $$2 to run, which isn't ideal";
- let tokens = tokenize(text);
+ let tokens = tokenize(text)?;
assert_eq!(
tokens,
TokenString(vec![
@@ -336,12 +340,13 @@ mod test {
token_text("2 to run, which isn't ideal"),
])
);
+ Ok(())
}
#[test]
- fn replacement() {
+ fn replacement() -> R {
let text = "Can I get a $(DATA:.c=.oof) in this ${SWAG:.yolo=}";
- let tokens = tokenize(text);
+ let tokens = tokenize(text)?;
assert_eq!(
tokens,
TokenString(vec![
@@ -359,12 +364,13 @@ mod test {
),
])
);
+ Ok(())
}
#[test]
- fn hell() {
+ fn hell() -> R {
let text = "$(OOF:${ouch:hi=hey} there=$(owie:$(my)=${bones})), bro.";
- let tokens = tokenize(text);
+ let tokens = tokenize(text)?;
assert_eq!(
tokens,
TokenString(vec![
@@ -387,5 +393,6 @@ mod test {
token_text(", bro."),
])
);
+ Ok(())
}
}