aboutsummaryrefslogtreecommitdiff
path: root/tests/rule_specific_macros.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/rule_specific_macros.rs')
-rw-r--r--tests/rule_specific_macros.rs86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/rule_specific_macros.rs b/tests/rule_specific_macros.rs
new file mode 100644
index 0000000..8cc9c12
--- /dev/null
+++ b/tests/rule_specific_macros.rs
@@ -0,0 +1,86 @@
+mod utils;
+
+use std::fs;
+use utils::{make, R};
+
+#[test]
+#[cfg(feature = "full")]
+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"]
+#[cfg(feature = "full")]
+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"]
+#[cfg(feature = "full")]
+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(())
+}