#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used)]
use super::makefile::emit_makefile;
use crate::ast::restricted::{Function, Literal, Type};
use crate::ast::{Expr, RestrictedAst, Stmt};
#[test]
fn test_MCOV_031_exec_with_empty_resolution() {
let ast = make_ast(vec![Stmt::Expr(Expr::FunctionCall {
name: "exec".to_string(),
args: vec![Expr::FunctionCall {
name: "__format_concat".to_string(),
args: vec![],
}],
})]);
let result = emit_makefile(&ast);
assert!(result.is_ok());
}
#[test]
fn test_MCOV_032_entry_point_not_found_returns_error() {
let ast = RestrictedAst {
functions: vec![Function {
name: "other".to_string(),
params: vec![],
return_type: Type::Void,
body: vec![],
}],
entry_point: "main".to_string(), };
let err = emit_makefile(&ast).unwrap_err();
assert!(
format!("{err}").contains("Entry point"),
"Expected entry point error, got: {err}"
);
}
#[test]
fn test_MCOV_033_phony_target_non_string_name_error() {
let ast = make_ast(vec![Stmt::Expr(Expr::FunctionCall {
name: "phony_target".to_string(),
args: vec![
Expr::Literal(Literal::I32(99)), Expr::Array(vec![]),
],
})]);
let err = emit_makefile(&ast).unwrap_err();
assert!(
format!("{err}").contains("string literal"),
"Expected string literal error, got: {err}"
);
}
#[test]
fn test_MCOV_034_extract_array_via_array_func_call() {
let ast = make_ast(vec![Stmt::Expr(Expr::FunctionCall {
name: "target".to_string(),
args: vec![
Expr::Literal(Literal::Str("my_target".to_string())),
Expr::FunctionCall {
name: "__array__".to_string(),
args: vec![
Expr::Literal(Literal::Str("dep1".to_string())),
Expr::Literal(Literal::Str("dep2".to_string())),
],
},
],
})]);
let result = emit_makefile(&ast).unwrap();
assert!(result.contains("my_target"));
assert!(result.contains("dep1") || result.contains("dep2"));
}
#[test]
fn test_MCOV_035_extract_array_variable_fallback() {
let ast = make_ast(vec![Stmt::Expr(Expr::FunctionCall {
name: "target".to_string(),
args: vec![
Expr::Literal(Literal::Str("t".to_string())),
Expr::Variable("deps".to_string()),
],
})]);
let result = emit_makefile(&ast).unwrap();
assert!(result.contains("t") || result.contains("DEPS"));
}
#[test]
fn test_MCOV_036_expr_to_string_unsupported_returns_error() {
let ast = make_ast(vec![Stmt::Expr(Expr::FunctionCall {
name: "target".to_string(),
args: vec![
Expr::Literal(Literal::Str("tgt".to_string())),
Expr::Array(vec![Expr::FunctionCall {
name: "unknown".to_string(),
args: vec![],
}]),
],
})]);
let result = emit_makefile(&ast);
let _ = result;
}
#[test]
fn test_MCOV_037_collect_variable_bindings_non_str_skipped() {
let ast = make_ast(vec![
Stmt::Let {
name: "port".to_string(),
value: Expr::Literal(Literal::I32(8080)),
declaration: true,
},
Stmt::Expr(Expr::FunctionCall {
name: "rash_println".to_string(),
args: vec![Expr::Variable("port".to_string())],
}),
]);
let result = emit_makefile(&ast).unwrap();
assert!(result.contains("8080") || result.contains("PORT"));
}
#[test]
fn test_MCOV_038_multiple_raw_output_stmts() {
let ast = make_ast(vec![
Stmt::Expr(Expr::FunctionCall {
name: "rash_println".to_string(),
args: vec![Expr::Literal(Literal::Str("CC := gcc".to_string()))],
}),
Stmt::Expr(Expr::FunctionCall {
name: "rash_println".to_string(),
args: vec![Expr::Literal(Literal::Str("CFLAGS := -O2".to_string()))],
}),
Stmt::Expr(Expr::FunctionCall {
name: "rash_println".to_string(),
args: vec![Expr::Literal(Literal::Str("".to_string()))],
}),
]);
let result = emit_makefile(&ast).unwrap();
assert!(result.contains("CC := gcc"));
assert!(result.contains("CFLAGS := -O2"));
}
#[test]
fn test_MCOV_039_dsl_path_let_only() {
let ast = make_ast(vec![Stmt::Let {
name: "version".to_string(),
value: Expr::Literal(Literal::Str("1.0.0".to_string())),
declaration: true,
}]);
let result = emit_makefile(&ast).unwrap();
assert!(result.contains("VERSION") && result.contains("1.0.0"));
}
#[test]
fn test_MCOV_040_target_line_with_multiple_deps() {
let ast = make_ast(vec![Stmt::Expr(Expr::FunctionCall {
name: "exec".to_string(),
args: vec![Expr::Literal(Literal::Str(
"all: build test lint".to_string(),
))],
})]);
let result = emit_makefile(&ast).unwrap();
assert!(result.contains("all"));
assert!(result.contains("build") || result.contains("test") || result.contains("lint"));
}