Switched to build.ps1
Some checks failed
CI / Test (Linux) (push) Has been cancelled
CI / Test (Windows MSVC) (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Format (push) Has been cancelled

- Batch script had issues reading from cargo toml file
- Issues were revealed in cargo test (awesome!)
- build.bat is now a wrapper for build.ps1
This commit is contained in:
Eric Ratliff
2026-02-22 22:08:33 -06:00
parent 1ede07df81
commit 7e8d7ecce5
5 changed files with 283 additions and 199 deletions

View File

@@ -749,10 +749,12 @@ fn test_cmake_lists_fetches_google_test() {
fn test_scripts_all_reference_anvil_toml() {
let tmp = extract_project("toml_refs");
// Build and upload scripts must read .anvil.toml for configuration
// Build and upload scripts must read .anvil.toml for configuration.
// On Windows, build.bat is a thin wrapper that calls build.ps1,
// so we check the .ps1 file for content.
let config_scripts = vec![
"build.sh",
"build.bat",
"build.ps1",
"upload.sh",
"upload.bat",
];
@@ -777,9 +779,11 @@ fn test_scripts_all_reference_anvil_toml() {
fn test_scripts_invoke_arduino_cli_not_anvil() {
let tmp = extract_project("no_anvil_dep");
// Build/upload/monitor scripts must invoke arduino-cli directly
// Build/upload/monitor scripts must invoke arduino-cli directly.
// On Windows, build.bat is a thin wrapper calling build.ps1,
// so we check the .ps1 file for content.
let scripts = vec![
"build.sh", "build.bat",
"build.sh", "build.ps1",
"upload.sh", "upload.bat",
"monitor.sh", "monitor.bat",
];
@@ -829,6 +833,10 @@ fn test_scripts_invoke_arduino_cli_not_anvil() {
|| trimmed.starts_with("Write-Host")
|| trimmed.starts_with("Write-Error")
|| trimmed.starts_with("Write-Warning")
|| trimmed.starts_with("Fail ")
|| trimmed.starts_with("Fail(")
|| trimmed.starts_with("Fail \"")
|| trimmed.starts_with("Fail @")
{
return false;
}
@@ -860,6 +868,7 @@ fn test_all_expected_scripts_exist() {
let expected = vec![
"build.sh",
"build.bat",
"build.ps1",
"upload.sh",
"upload.bat",
"monitor.sh",

View File

@@ -574,7 +574,9 @@ fn test_sh_scripts_have_toml_section_get() {
#[test]
fn test_bat_scripts_have_section_parser() {
// Batch scripts need section-aware TOML parsing for board profiles
// Windows scripts need section-aware TOML parsing for board profiles.
// build.bat delegates to build.ps1; upload.bat and monitor.bat may
// still use batch-native parsing or their own .ps1 backends.
let tmp = TempDir::new().unwrap();
let ctx = TemplateContext {
project_name: "bat_section".to_string(),
@@ -585,12 +587,33 @@ fn test_bat_scripts_have_section_parser() {
};
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
for bat in &["build.bat", "upload.bat", "monitor.bat"] {
let content = fs::read_to_string(tmp.path().join(bat)).unwrap();
// Check each Windows script OR its PowerShell backend for section parsing
let pairs: &[(&str, &str)] = &[
("build.bat", "build.ps1"),
("upload.bat", "upload.ps1"),
("monitor.bat", "monitor.ps1"),
];
for (bat, ps1) in pairs {
let bat_path = tmp.path().join(bat);
let ps1_path = tmp.path().join(ps1);
let has_parser = if ps1_path.exists() {
// PowerShell backend handles TOML parsing
let content = fs::read_to_string(&ps1_path).unwrap();
content.contains("boards.") || content.contains("currentSection")
} else if bat_path.exists() {
// Batch does its own section parsing
let content = fs::read_to_string(&bat_path).unwrap();
content.contains("BOARD_SECTION") || content.contains("IN_SECTION")
} else {
false
};
assert!(
content.contains("BOARD_SECTION") || content.contains("IN_SECTION"),
"{} should have section parser for board profiles",
bat
has_parser,
"{} (or {}) should have section parser for board profiles",
bat, ps1
);
}
}

View File

@@ -489,7 +489,7 @@ fn test_refresh_freshly_extracted_is_up_to_date() {
TemplateManager::extract("basic", reference.path(), &ctx).unwrap();
let refreshable = vec![
"build.sh", "build.bat",
"build.sh", "build.bat", "build.ps1",
"upload.sh", "upload.bat",
"monitor.sh", "monitor.bat",
"test.sh", "test.bat",
@@ -561,7 +561,7 @@ fn test_refresh_does_not_list_user_files() {
];
let refreshable = vec![
"build.sh", "build.bat",
"build.sh", "build.bat", "build.ps1",
"upload.sh", "upload.bat",
"monitor.sh", "monitor.bat",
"test.sh", "test.bat",
@@ -644,12 +644,14 @@ fn test_scripts_read_default_board() {
);
}
for bat in &["build.bat", "upload.bat", "monitor.bat"] {
let content = fs::read_to_string(tmp.path().join(bat)).unwrap();
// build.bat is now a thin wrapper; build.ps1 has the real logic.
// upload.bat and monitor.bat still have batch-native parsing.
for script in &["build.ps1", "upload.bat", "monitor.bat"] {
let content = fs::read_to_string(tmp.path().join(script)).unwrap();
assert!(
content.contains("DEFAULT_BOARD"),
"{} should read default field into DEFAULT_BOARD",
bat
content.contains("DEFAULT_BOARD") || content.contains("DefaultBoard") || content.contains("default"),
"{} should read default field for board selection",
script
);
}
}
@@ -674,8 +676,9 @@ fn test_scripts_use_compiler_extra_flags_not_build() {
};
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
// build.bat is a thin wrapper; check build.ps1 for content
let compile_scripts = vec![
"build.sh", "build.bat",
"build.sh", "build.ps1",
"upload.sh", "upload.bat",
];
@@ -743,8 +746,9 @@ fn test_script_errors_show_manual_fix() {
};
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
// build.bat is a thin wrapper; check build.ps1 for content
let all_scripts = vec![
"build.sh", "build.bat",
"build.sh", "build.ps1",
"upload.sh", "upload.bat",
"monitor.sh", "monitor.bat",
];
@@ -752,7 +756,7 @@ fn test_script_errors_show_manual_fix() {
for script in &all_scripts {
let content = fs::read_to_string(tmp.path().join(script)).unwrap();
assert!(
content.contains("default = "),
content.contains("default = ") || content.contains("default ="),
"{} error messages should show the manual fix (default = \"...\")",
script
);
@@ -773,8 +777,9 @@ fn test_script_errors_mention_arduino_cli() {
};
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
// build.bat is a thin wrapper; check build.ps1 for content
let all_scripts = vec![
"build.sh", "build.bat",
"build.sh", "build.ps1",
"upload.sh", "upload.bat",
"monitor.sh", "monitor.bat",
];
@@ -803,8 +808,8 @@ fn test_script_errors_mention_toml_section_syntax() {
};
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
// build and upload scripts have both no-default and board-not-found errors
for script in &["build.sh", "build.bat", "upload.sh", "upload.bat"] {
// build.bat is a thin wrapper; check build.ps1 for content
for script in &["build.sh", "build.ps1", "upload.sh", "upload.bat"] {
let content = fs::read_to_string(tmp.path().join(script)).unwrap();
assert!(
content.contains("[boards."),
@@ -932,11 +937,12 @@ fn test_build_scripts_autodiscover_driver_includes() {
};
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
// build.bat is a thin wrapper; check build.ps1 for content.
// All four compile scripts must auto-discover lib/drivers/*
for script in &["build.sh", "upload.sh", "build.bat", "upload.bat"] {
for script in &["build.sh", "upload.sh", "build.ps1", "upload.bat"] {
let content = fs::read_to_string(tmp.path().join(script)).unwrap();
assert!(
content.contains("lib/drivers") || content.contains("lib\\drivers"),
content.contains("lib/drivers") || content.contains("lib\\drivers") || content.contains("lib\\\\drivers"),
"{} must auto-discover lib/drivers/* for library include paths",
script
);