Files
diodeinc__pcb/crates/pcb-layout/tests/layout_generation.rs
Akhil Velagapudi ae7766a8a6 Add warnings for unstable refs in load(), Module() (#105)
* Refactor diagnostics for warnings support

- Add render trait
- Render warnings after errors
- Reuse build code across build, layout

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Delete bundle

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Fix clippy lints

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Add git ref metadata

3 stages to fetch_remote:
- Ensure remote is in cache
- Add appropriate symlinks
- Classify + store ref metadata

Some code cleanup:
- Factored out some git clone dupe code
- Centralized git operations in git.rs

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Warn on unstable refs

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Add "-Dwarnings" flag to error on warnings

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Warn on unstable refs in Module()

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Add snapshot tests for warnings

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Fix span detection for chained Module()

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Add ResolveContext, dedup resolve code

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Use spec history for better alias warnings

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Add pcb.toml spans

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Add type-erased error storage to Diagnostic

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Fix bug with load() span detection

The previous logic would just attempt to match by path, but if there are
multiple load() statements in a single file with the same path, then
find_load_span_for_path with always return the first.

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Added diagnostics passes

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Add LSP-specific pass to filter out some warnings

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Fix rebase conflicts

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

* Fix unstable ref detection logic

If we clone by tag and the tag exists in the git repo, it's a stable
ref. Same with commit.

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>

---------

Signed-off-by: akhilles <akhilvelagapudi@gmail.com>
2025-08-25 15:45:51 -07:00

82 lines
2.8 KiB
Rust

use anyhow::Result;
use assert_fs::prelude::*;
use assert_fs::TempDir;
use pcb_layout::process_layout;
use serial_test::serial;
mod helpers;
use helpers::*;
macro_rules! layout_test {
($name:expr, $board_name:expr) => {
paste::paste! {
#[test]
#[serial]
fn [<test_layout_generation_with_ $name:snake>]() -> Result<()> {
// Create a temp directory and copy the test resources
let temp = TempDir::new()?.into_persistent();
let resource_path = get_resource_path($name);
temp.copy_from(&resource_path, &["**/*", "!.pcb/cache/**/*"])?;
// Find and evaluate the board zen file
let zen_file = temp.path().join(format!("{}.zen", $board_name));
assert!(zen_file.exists(), "{}.zen should exist", $board_name);
// Evaluate the Zen file to generate a schematic
let (output, diagnostics) = pcb_zen::run(&zen_file, false).unpack();
// Check for errors in evaluation
if !diagnostics.is_empty() {
eprintln!("Zen evaluation diagnostics:");
for diag in diagnostics {
eprintln!(" {:?}", diag);
}
}
let schematic = output.expect("Zen evaluation should produce a schematic");
// Process the layout
let result = process_layout(&schematic, &zen_file)?;
// Verify the layout was created
assert!(result.pcb_file.exists(), "PCB file should exist");
assert!(result.netlist_file.exists(), "Netlist file should exist");
assert!(result.snapshot_file.exists(), "Snapshot file should exist");
assert!(result.log_file.exists(), "Log file should exist");
// Print the log file contents
let log_contents = std::fs::read_to_string(&result.log_file)?;
println!("Layout log file contents:");
println!("========================");
println!("{}", log_contents);
println!("========================");
// Check the snapshot matches
assert_file_snapshot!(
format!("{}.layout.json", $name),
result.snapshot_file
);
Ok(())
}
}
};
}
// Schematic: A couple BMI270 modules in Starlark.
layout_test!("simple", "MyBoard");
layout_test!("module_layout", "Main");
layout_test!("component_side_sync", "Board");
layout_test!("multi_pads", "MultiPads");
layout_test!("dnp", "MyBoard");
layout_test!("zones", "Board");
layout_test!("graphics", "Board");
layout_test!("complex", "Board");