diff options
author | Melody Horn <melody@boringcactus.com> | 2024-11-11 17:15:08 -0700 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2024-11-11 17:15:08 -0700 |
commit | 4f9299b4639802e05e1cb27d8eb40305ff8e110e (patch) | |
tree | 0da5529c68c82e97aed67d842e50f6285e79e6c2 /tests/rule_specific_macros.rs | |
parent | fbbcf325b8bbe72f924da6a7cdb128d973ef0026 (diff) | |
download | makers-4f9299b4639802e05e1cb27d8eb40305ff8e110e.tar.gz makers-4f9299b4639802e05e1cb27d8eb40305ff8e110e.zip |
implement rule-specific macros for targets
Diffstat (limited to 'tests/rule_specific_macros.rs')
-rw-r--r-- | tests/rule_specific_macros.rs | 86 |
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(()) +} |