Added timestamps to project logging
This commit is contained in:
@@ -831,6 +831,7 @@ fn test_full_project_structure() {
|
||||
"monitor.sh",
|
||||
"monitor.bat",
|
||||
"_detect_port.ps1",
|
||||
"_monitor_filter.ps1",
|
||||
"test/CMakeLists.txt",
|
||||
"test/test_unit.cpp",
|
||||
"test/run_tests.sh",
|
||||
@@ -1414,6 +1415,7 @@ fn test_refresh_freshly_extracted_is_up_to_date() {
|
||||
"upload.sh", "upload.bat",
|
||||
"monitor.sh", "monitor.bat",
|
||||
"_detect_port.ps1",
|
||||
"_monitor_filter.ps1",
|
||||
"test/run_tests.sh", "test/run_tests.bat",
|
||||
];
|
||||
|
||||
@@ -1478,6 +1480,7 @@ fn test_refresh_does_not_list_user_files() {
|
||||
"upload.sh", "upload.bat",
|
||||
"monitor.sh", "monitor.bat",
|
||||
"_detect_port.ps1",
|
||||
"_monitor_filter.ps1",
|
||||
"test/run_tests.sh", "test/run_tests.bat",
|
||||
];
|
||||
|
||||
@@ -1865,4 +1868,106 @@ fn test_script_errors_mention_toml_section_syntax() {
|
||||
script
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// Monitor: --timestamps and --log flags
|
||||
// ==========================================================================
|
||||
|
||||
#[test]
|
||||
fn test_monitor_scripts_accept_timestamps_flag() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = TemplateContext {
|
||||
project_name: "ts_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
board_name: "uno".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
for script in &["monitor.sh", "monitor.bat"] {
|
||||
let content = fs::read_to_string(tmp.path().join(script)).unwrap();
|
||||
assert!(
|
||||
content.contains("--timestamps"),
|
||||
"{} should accept --timestamps flag",
|
||||
script
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_monitor_scripts_accept_log_flag() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = TemplateContext {
|
||||
project_name: "log_test".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
board_name: "uno".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
for script in &["monitor.sh", "monitor.bat"] {
|
||||
let content = fs::read_to_string(tmp.path().join(script)).unwrap();
|
||||
assert!(
|
||||
content.contains("--log"),
|
||||
"{} should accept --log flag for file output",
|
||||
script
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_monitor_sh_has_timestamp_format() {
|
||||
// The timestamp format should include hours, minutes, seconds, and millis
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = TemplateContext {
|
||||
project_name: "ts_fmt".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
board_name: "uno".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
let content = fs::read_to_string(tmp.path().join("monitor.sh")).unwrap();
|
||||
assert!(
|
||||
content.contains("%H:%M:%S"),
|
||||
"monitor.sh should use HH:MM:SS timestamp format"
|
||||
);
|
||||
assert!(
|
||||
content.contains("%3N"),
|
||||
"monitor.sh should include milliseconds in timestamps"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_monitor_sh_timestamps_work_in_watch_mode() {
|
||||
// The timestamp filter should also apply in --watch mode
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = TemplateContext {
|
||||
project_name: "watch_ts".to_string(),
|
||||
anvil_version: "1.0.0".to_string(),
|
||||
board_name: "uno".to_string(),
|
||||
fqbn: "arduino:avr:uno".to_string(),
|
||||
baud: 115200,
|
||||
};
|
||||
TemplateManager::extract("basic", tmp.path(), &ctx).unwrap();
|
||||
|
||||
let content = fs::read_to_string(tmp.path().join("monitor.sh")).unwrap();
|
||||
|
||||
// The filter function should be called in the watch loop
|
||||
assert!(
|
||||
content.contains("monitor_filter"),
|
||||
"monitor.sh should use a filter function for timestamps"
|
||||
);
|
||||
|
||||
// Count usages of monitor_filter - should appear in both watch and non-watch
|
||||
let filter_count = content.matches("monitor_filter").count();
|
||||
assert!(
|
||||
filter_count >= 3,
|
||||
"monitor_filter should be defined and used in both watch and normal mode (found {} refs)",
|
||||
filter_count
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user