aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conditional_assignment_inheritance.rs29
-rw-r--r--tests/rule_specific_macros.rs85
-rw-r--r--tests/update_logic.rs14
-rw-r--r--tests/utils/mod.rs13
4 files changed, 129 insertions, 12 deletions
diff --git a/tests/conditional_assignment_inheritance.rs b/tests/conditional_assignment_inheritance.rs
new file mode 100644
index 0000000..24f0533
--- /dev/null
+++ b/tests/conditional_assignment_inheritance.rs
@@ -0,0 +1,29 @@
+#![cfg(feature = "full")]
+
+mod utils;
+
+use std::fs;
+use utils::{make, R};
+
+#[test]
+fn conditional_assignment_inheritance_test() -> R {
+ let dir = tempfile::tempdir()?;
+
+ let file_a = "
+EGG = bug
+include file_b.mk
+check:
+\t@echo $(EGG)
+";
+ fs::write(dir.path().join("Makefile"), file_a)?;
+ let file_b = "
+EGG ?= nope
+";
+ fs::write(dir.path().join("file_b.mk"), file_b)?;
+
+ let result = make(&dir)?;
+ assert!(result.status.success());
+ assert_eq!(String::from_utf8(result.stdout)?.trim(), "bug");
+
+ Ok(())
+}
diff --git a/tests/rule_specific_macros.rs b/tests/rule_specific_macros.rs
new file mode 100644
index 0000000..34e7e77
--- /dev/null
+++ b/tests/rule_specific_macros.rs
@@ -0,0 +1,85 @@
+#![cfg(feature = "full")]
+
+mod utils;
+
+use std::fs;
+use utils::{make, R};
+
+#[test]
+fn target_specific_macros() -> R {
+ let dir = tempfile::tempdir()?;
+
+ let file = "
+foo.h: EGG = bug
+foo.h:
+\techo $(EGG)
+ ";
+ fs::write(dir.path().join("Makefile"), file)?;
+
+ let result = make(&dir)?;
+ dbg!(&result);
+ assert!(result.status.success());
+ let stdout = String::from_utf8(result.stdout)?;
+ assert!(stdout.contains("echo bug"));
+
+ Ok(())
+}
+
+#[test]
+#[ignore = "not yet implemented"]
+fn target_specific_macros_inherited() -> R {
+ let dir = tempfile::tempdir()?;
+
+ // example from https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html
+ let file = "
+CC=echo cc
+prog : CFLAGS = -g
+prog : prog.o foo.o bar.o
+ ";
+ fs::write(dir.path().join("Makefile"), file)?;
+ fs::write(dir.path().join("prog.c"), "")?;
+ fs::write(dir.path().join("foo.c"), "")?;
+ fs::write(dir.path().join("bar.c"), "")?;
+
+ let result = make(&dir)?;
+ dbg!(&result);
+ assert!(result.status.success());
+ let stdout = String::from_utf8(result.stdout)?;
+ assert!(stdout.contains("echo cc -g -c foo.c"));
+ assert!(stdout.contains("echo cc -g -c bar.o"));
+ assert!(stdout.contains("echo cc -g -c prog.c"));
+
+ Ok(())
+}
+
+#[test]
+#[ignore = "not yet implemented"]
+fn inference_rule_specific_macros() -> R {
+ let dir = tempfile::tempdir()?;
+
+ // example from https://www.gnu.org/software/make/manual/html_node/Pattern_002dspecific.html
+ let file = "
+CC=echo cc
+%.o: %.c
+\t$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
+
+lib/%.o: CFLAGS := -fPIC -g
+%.o: CFLAGS := -g
+
+all: foo.o lib/bar.o
+ ";
+ fs::write(dir.path().join("Makefile"), file)?;
+ fs::write(dir.path().join("foo.c"), "")?;
+ fs::create_dir(dir.path().join("lib"))?;
+ fs::write(dir.path().join("bar.c"), "")?;
+
+ let result = make(&dir)?;
+ dbg!(&result);
+ assert!(result.status.success());
+ let stdout = String::from_utf8(result.stdout)?;
+ dbg!(&stdout);
+ assert!(stdout.contains("echo cc -g foo.c -o foo.o"));
+ assert!(stdout.contains("echo cc -fPIC -g lib/bar.c -o lib/bar.o"));
+
+ Ok(())
+}
diff --git a/tests/update_logic.rs b/tests/update_logic.rs
index 9e37b19..6eefe6b 100644
--- a/tests/update_logic.rs
+++ b/tests/update_logic.rs
@@ -1,19 +1,9 @@
use std::fs;
-use std::path::Path;
-use std::process::{Command, Output};
-
-use eyre::{Result, WrapErr};
use std::thread::sleep;
use std::time::Duration;
-type R = Result<()>;
-
-fn make(dir: impl AsRef<Path>) -> Result<Output> {
- Command::new(env!("CARGO_BIN_EXE_makers"))
- .current_dir(dir)
- .output()
- .wrap_err("")
-}
+mod utils;
+use utils::{make, R};
#[test]
fn basic_test() -> R {
diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs
new file mode 100644
index 0000000..8b834c1
--- /dev/null
+++ b/tests/utils/mod.rs
@@ -0,0 +1,13 @@
+use std::path::Path;
+use std::process::{Command, Output};
+
+use eyre::Context;
+
+pub type R = eyre::Result<()>;
+
+pub fn make(dir: impl AsRef<Path>) -> eyre::Result<Output> {
+ Command::new(env!("CARGO_BIN_EXE_makers"))
+ .current_dir(dir)
+ .output()
+ .wrap_err("")
+}