Something went wrong. Try again.
A human-friendly DSL for ATProto Lexicons forked from stavola.xyz/mlf
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677// Workspace-level integration tests for diagnostics.//// Each subdirectory of `diagnostics/` is a fixture with `input.mlf`// and `test.toml`. Expected diagnostics are captured as an insta// `.snap` file checked into the fixture directory.//// To update snapshots after an intentional change:// just test-diagnostics # produces .snap.new files// just review # interactive accept/reject
use mlf_diagnostics::{get_error_module_namespace_str, ValidationDiagnostic};use mlf_integration_tests::test_utils;use mlf_lang::{parser::parse_lexicon, Workspace};use std::fs;use std::path::Path;
fn run_diagnostics_test(input_path: &Path) -> datatest_stable::Result<()> { let test_dir = input_path .parent() .ok_or("input.mlf has no parent directory")?; let test_name = test_dir .file_name() .and_then(|s| s.to_str()) .ok_or("input.mlf parent has no name")? .to_string();
let config = test_utils::load_test_config(test_dir, |name| format!("test.{}", name)) .map_err(|e| format!("{}", e))?;
let namespace = config .test .namespace .ok_or("No namespace specified in test.toml")?;
let input = fs::read_to_string(input_path)?; let lexicon = parse_lexicon(&input).map_err(|e| format!("Failed to parse: {:?}", e))?;
let mut ws = Workspace::with_std().map_err(|e| format!("Failed to create workspace: {:?}", e))?; ws.add_module(namespace.clone(), lexicon) .map_err(|e| format!("Failed to add module: {:?}", e))?;
let validation_errors = match ws.resolve() { Ok(()) => return Err("Expected validation errors but got none".into()), Err(errors) => errors, };
// Construct the diagnostic to verify the wiring compiles and runs. let _diagnostic = ValidationDiagnostic::new( "input.mlf".to_string(), input.clone(), namespace.clone(), validation_errors.clone(), );
let errors_in_module: Vec<String> = validation_errors .errors .iter() .filter(|e| get_error_module_namespace_str(e) == namespace) .map(|e| format!("{:?}", e)) .collect();
insta::with_settings!({ snapshot_path => test_dir.to_path_buf(), prepend_module_to_snapshot => false, snapshot_suffix => test_name, }, { insta::assert_debug_snapshot!("errors", errors_in_module); });
Ok(())}
datatest_stable::harness! { { test = run_diagnostics_test, root = "diagnostics", pattern = r"^.*/input\.mlf$" },}