Skip to content

Commit 1ec480e

Browse files
committed
Add macro case
1 parent 0661b6e commit 1ec480e

File tree

1 file changed

+34
-1
lines changed
  • crates/vespertide-macro/src

1 file changed

+34
-1
lines changed

crates/vespertide-macro/src/lib.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,23 @@ mod tests {
293293

294294
#[test]
295295
fn test_macro_parsing_valid_input() {
296-
// Test that valid input is parsed correctly (even though migration loading fails)
296+
// Test that valid input is parsed correctly
297+
// The macro will either succeed (if migrations dir exists and is empty)
298+
// or fail with a migration loading error
297299
let input: proc_macro2::TokenStream = "my_pool".parse().unwrap();
298300
let output = vespertide_migration_impl(input);
299301
let output_str = output.to_string();
300302
// Should produce output (either success or migration loading error)
301303
assert!(!output_str.is_empty());
304+
// If error, it should mention "Failed to load"
305+
// If success, it should contain "async"
306+
assert!(
307+
output_str.contains("async") || output_str.contains("Failed to load"),
308+
"Unexpected output: {}",
309+
output_str
310+
);
311+
// Print for debugging coverage
312+
eprintln!("Output contains 'async': {}", output_str.contains("async"));
302313
}
303314

304315
#[test]
@@ -616,4 +627,26 @@ mod tests {
616627
let normalized = table.clone().normalize();
617628
assert!(normalized.is_ok());
618629
}
630+
631+
#[test]
632+
fn test_build_migration_block_error_nonexistent_table() {
633+
// Try to add column to a table that doesn't exist - should fail
634+
let migration = MigrationPlan {
635+
version: 1,
636+
comment: None,
637+
created_at: None,
638+
actions: vec![MigrationAction::AddColumn {
639+
table: "nonexistent_table".into(),
640+
column: Box::new(test_column("new_col")),
641+
fill_with: None,
642+
}],
643+
};
644+
645+
let mut baseline = Vec::new();
646+
let result = build_migration_block(&migration, &mut baseline);
647+
648+
assert!(result.is_err());
649+
let err = result.unwrap_err();
650+
assert!(err.contains("Failed to build queries for migration version 1"));
651+
}
619652
}

0 commit comments

Comments
 (0)