Add board presets, devices --clear, and test/UX fixes
Board presets: - anvil new --board mega (uno, mega, nano, nano-old, leonardo, micro) - anvil new --list-boards shows presets with compatible clones - FQBN and baud rate flow into .anvil.toml via template variables - Defaults to uno when --board is omitted Devices --clear: - anvil devices --clear deletes .anvil.local, reverts to auto-detect
This commit is contained in:
@@ -15,6 +15,8 @@ fn test_basic_template_extracts_all_expected_files() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "test_proj".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
let count = TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -27,6 +29,8 @@ fn test_template_creates_sketch_directory() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "blink".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -55,6 +59,8 @@ fn test_template_creates_hal_files() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "sensor".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -86,6 +92,8 @@ fn test_template_creates_app_header() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "my_sensor".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -110,6 +118,8 @@ fn test_template_creates_test_infrastructure() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "blink".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -146,6 +156,8 @@ fn test_template_test_file_references_correct_app() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "motor_ctrl".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -165,6 +177,8 @@ fn test_template_cmake_references_correct_project() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "my_bot".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -184,6 +198,8 @@ fn test_template_creates_dot_files() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "blink".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -212,6 +228,8 @@ fn test_template_creates_readme() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "blink".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -233,6 +251,8 @@ fn test_template_creates_valid_config() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "blink".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -312,6 +332,8 @@ fn test_full_project_structure() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "full_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -361,6 +383,8 @@ fn test_no_unicode_in_template_output() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "ascii_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -408,6 +432,8 @@ fn test_unknown_template_fails() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
let result = TemplateManager::extract("nonexistent", tmp.path(), &ctx);
|
||||
@@ -431,6 +457,8 @@ fn test_template_creates_self_contained_scripts() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "standalone".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -453,6 +481,8 @@ fn test_build_sh_reads_anvil_toml() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "toml_reader".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -478,6 +508,8 @@ fn test_upload_sh_reads_anvil_toml() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "uploader".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -511,6 +543,8 @@ fn test_monitor_sh_reads_anvil_toml() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "serial_mon".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -536,6 +570,8 @@ fn test_scripts_have_shebangs() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "shebangs".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -558,6 +594,8 @@ fn test_scripts_no_anvil_binary_dependency() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "no_anvil_dep".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -605,6 +643,8 @@ fn test_gitignore_excludes_build_cache() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "gitcheck".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -630,6 +670,8 @@ fn test_readme_documents_self_contained_workflow() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "docs_check".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -663,6 +705,8 @@ fn test_scripts_tolerate_missing_toml_keys() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "grep_safe".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
@@ -698,6 +742,8 @@ fn test_bat_scripts_no_unescaped_parens_in_echo() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "parens_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
@@ -757,6 +803,8 @@ fn test_scripts_read_anvil_local_for_port() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "local_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
@@ -777,6 +825,8 @@ fn test_anvil_toml_template_has_no_port() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "no_port".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
@@ -806,6 +856,8 @@ fn test_bat_scripts_call_detect_port_ps1() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "ps1_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
@@ -826,6 +878,8 @@ fn test_detect_port_ps1_is_valid() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "ps1_valid".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
@@ -856,6 +910,8 @@ fn test_refresh_freshly_extracted_is_up_to_date() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "fresh_proj".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
@@ -884,6 +940,8 @@ fn test_refresh_detects_modified_script() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "mod_proj".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
@@ -951,6 +1009,8 @@ fn test_scripts_read_vid_pid_from_anvil_local() {
|
||||
let ctx = TemplateContext {
|
||||
project_name: "vidpid_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
@@ -962,4 +1022,44 @@ fn test_scripts_read_vid_pid_from_anvil_local() {
|
||||
script
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// Board preset tests
|
||||
// ==========================================================================
|
||||
|
||||
#[test]
|
||||
fn test_board_preset_fqbn_in_config() {
|
||||
// Creating a project with --board mega should set the FQBN in .anvil.toml
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = TemplateContext {
|
||||
project_name: "mega_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "arduino:avr:mega:cpu=atmega2560".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
let config = ProjectConfig::load(tmp.path()).unwrap();
|
||||
assert_eq!(
|
||||
config.build.fqbn, "arduino:avr:mega:cpu=atmega2560",
|
||||
".anvil.toml should contain mega FQBN"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_board_preset_custom_fqbn_in_config() {
|
||||
// Even arbitrary FQBNs should work through the template
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = TemplateContext {
|
||||
project_name: "custom_board".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
fqbn: "esp32:esp32:esp32".to_string(),
|
||||
baud: 9600,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
let config = ProjectConfig::load(tmp.path()).unwrap();
|
||||
assert_eq!(config.build.fqbn, "esp32:esp32:esp32");
|
||||
assert_eq!(config.monitor.baud, 9600);
|
||||
}
|
||||
Reference in New Issue
Block a user