#![allow(clippy::unwrap_used)]
#![allow(unused_imports)]
use super::super::*;
use crate::make_parser::ast::{MakeCondition, Span, VarFlavor};
#[test]
fn test_RULE_SYNTAX_001_basic_rule_syntax() {
let makefile = "target: prerequisites\n\trecipe";
let result = parse_makefile(makefile);
assert!(
result.is_ok(),
"Should parse basic rule syntax, got error: {:?}",
result.err()
);
let ast = result.unwrap();
assert_eq!(
ast.items.len(),
1,
"Should have exactly one item, got {}",
ast.items.len()
);
match &ast.items[0] {
MakeItem::Target {
name,
prerequisites,
recipe,
phony,
..
} => {
assert_eq!(name, "target", "Target name should be 'target'");
assert_eq!(prerequisites.len(), 1, "Should have one prerequisite");
assert_eq!(
prerequisites[0], "prerequisites",
"Prerequisite should be 'prerequisites'"
);
assert_eq!(recipe.len(), 1, "Should have one recipe line");
assert_eq!(recipe[0], "recipe", "Recipe should be 'recipe'");
assert!(!(*phony), "Should not be marked as phony initially");
}
other => panic!("Expected Target item, got {:?}", other),
}
}
#[test]
fn test_RULE_SYNTAX_001_multiple_prerequisites() {
let makefile = "all: build test deploy";
let result = parse_makefile(makefile);
assert!(result.is_ok());
let ast = result.unwrap();
assert_eq!(ast.items.len(), 1);
match &ast.items[0] {
MakeItem::Target {
name,
prerequisites,
..
} => {
assert_eq!(name, "all");
assert_eq!(prerequisites.len(), 3);
assert_eq!(prerequisites[0], "build");
assert_eq!(prerequisites[1], "test");
assert_eq!(prerequisites[2], "deploy");
}
_ => panic!("Expected Target item"),
}
}
#[test]
fn test_RULE_SYNTAX_001_empty_recipe() {
let makefile = "target: prerequisites";
let result = parse_makefile(makefile);
assert!(result.is_ok());
let ast = result.unwrap();
assert_eq!(ast.items.len(), 1);
match &ast.items[0] {
MakeItem::Target { recipe, .. } => {
assert_eq!(recipe.len(), 0, "Recipe should be empty");
}
_ => panic!("Expected Target item"),
}
}
#[test]
fn test_RULE_SYNTAX_001_multiline_recipe() {
let makefile =
"deploy:\n\tcargo build --release\n\tcargo test\n\tscp target/release/app server:/opt/";
let result = parse_makefile(makefile);
assert!(result.is_ok());
let ast = result.unwrap();
assert_eq!(ast.items.len(), 1);
match &ast.items[0] {
MakeItem::Target { recipe, .. } => {
assert_eq!(recipe.len(), 3, "Should have 3 recipe lines");
assert_eq!(recipe[0], "cargo build --release");
assert_eq!(recipe[1], "cargo test");
assert_eq!(recipe[2], "scp target/release/app server:/opt/");
}
_ => panic!("Expected Target item"),
}
}
#[cfg(test)]
#[path = "part1_tests_rule_syntax.rs"]
mod tests_extracted;