Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[naga]: Make snapshot tests include paths in errors. #4742

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions naga-cli/src/bin/naga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
match result {
Ok(v) => (v, Some(input)),
Err(ref e) => {
let path = input_path.to_string_lossy();
e.emit_to_stderr_with_path(&input, &path);
e.emit_to_stderr_with_path(&input, input_path);
return Err(CliError("Could not parse WGSL").into());
}
}
Expand Down
12 changes: 10 additions & 2 deletions naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ impl ParseError {
}

/// Emits a summary of the error to standard error stream.
pub fn emit_to_stderr_with_path(&self, source: &str, path: &str) {
pub fn emit_to_stderr_with_path<P>(&self, source: &str, path: P)
where
P: AsRef<std::path::Path>,
{
let path = path.as_ref().display().to_string();
let files = SimpleFile::new(path, source);
let config = codespan_reporting::term::Config::default();
let writer = StandardStream::stderr(ColorChoice::Auto);
Expand All @@ -69,7 +73,11 @@ impl ParseError {
}

/// Emits a summary of the error to a string.
pub fn emit_to_string_with_path(&self, source: &str, path: &str) -> String {
pub fn emit_to_string_with_path<P>(&self, source: &str, path: P) -> String
where
P: AsRef<std::path::Path>,
{
let path = path.as_ref().display().to_string();
let files = SimpleFile::new(path, source);
let config = codespan_reporting::term::Config::default();
let mut writer = NoColor::new(Vec::new());
Expand Down
10 changes: 8 additions & 2 deletions naga/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,10 @@ fn convert_wgsl() {
let source = input.read_source();
match naga::front::wgsl::parse_str(&source) {
Ok(mut module) => check_targets(&input, &mut module, targets, None),
Err(e) => panic!("{}", e.emit_to_string(&source)),
Err(e) => panic!(
"{}",
e.emit_to_string_with_path(&source, input.input_path())
),
}
}

Expand All @@ -798,7 +801,10 @@ fn convert_wgsl() {
let source = input.read_source();
match naga::front::wgsl::parse_str(&source) {
Ok(mut module) => check_targets(&input, &mut module, targets, Some(&source)),
Err(e) => panic!("{}", e.emit_to_string(&source)),
Err(e) => panic!(
"{}",
e.emit_to_string_with_path(&source, input.input_path())
),
}
}
}
Expand Down
Loading