Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fix(rome_cli): Fix max diagnostic counts
Browse files Browse the repository at this point in the history
Fix symlink tests
  • Loading branch information
Micha Reiser committed Nov 26, 2022
1 parent a5168e0 commit a0c84ce
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 79 deletions.
10 changes: 2 additions & 8 deletions crates/rome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,7 @@ fn fs_error_dereferenced_symlink() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
#[cfg(target_family = "unix")]
"fs_error_dereferenced_symlink_unix",
#[cfg(target_os = "windows")]
"fs_error_dereferenced_symlink_windows",
"fs_error_dereferenced_symlink",
fs,
console,
result,
Expand Down Expand Up @@ -789,10 +786,7 @@ fn fs_error_infinite_symlink_exapansion() {

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
#[cfg(target_family = "unix")]
"fs_error_infinite_symlink_exapansion_unix",
#[cfg(target_os = "windows")]
"fs_error_infinite_symlink_exapansion_windows",
"fs_error_infinite_symlink_expansion",
fs,
console,
result,
Expand Down
45 changes: 41 additions & 4 deletions crates/rome_cli/tests/snap_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ fn redact_snapshot(input: &str) -> Cow<'_, str> {
replace(&mut output, &current_exe, "rome");
}

// Replace the path to the temporary directory with "<TEMP_DIR>"
let temp_dir = temp_dir().display().to_string();
let temp_dir = temp_dir.trim_end_matches(MAIN_SEPARATOR);
replace(&mut output, temp_dir, "<TEMP_DIR>");
output = replace_temp_dir(output);

// Normalize Windows-specific path separators to "/"
if cfg!(windows) {
Expand Down Expand Up @@ -173,6 +170,46 @@ fn redact_snapshot(input: &str) -> Cow<'_, str> {
output
}

/// Replace the path to the temporary directory with "<TEMP_DIR>"
/// And normalizes the count of `-` at the end of the diagnostic
fn replace_temp_dir(input: Cow<str>) -> Cow<str> {
let mut result = String::new();
let mut rest = input.as_ref();

let temp_dir = temp_dir().display().to_string();
let temp_dir = temp_dir.trim_end_matches(MAIN_SEPARATOR);

while let Some(index) = rest.find(temp_dir) {
let (before, after) = rest.split_at(index);

result.push_str(before);
result.push_str("<TEMP_DIR>");

let after = after.split_at(temp_dir.len()).1;
let header_line = after.lines().next().unwrap();

match header_line.split_once('\u{2501}') {
Some((between_temp_and_line, _)) => {
// Diagnostic header line, normalize the horizontal line
result.push_str(between_temp_and_line);
result.push_str(&"\u{2501}".repeat(20));
rest = after.split_at(header_line.len()).1;
}
None => {
// Not a header line, only replace tempdir
rest = after;
}
}
}

if result.is_empty() {
input
} else {
result.push_str(rest);
Cow::Owned(result)
}
}

fn replace(input: &mut Cow<str>, from: &str, to: &str) {
let mut rest = &**input;
let mut result = String::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ no files were processed in the specified paths.
# Emitted Messages

```block
<TEMP_DIR>/rome_test_broken_symlink/broken_symlink internalError/fs ━━━━━━━━━━
<TEMP_DIR>/rome_test_broken_symlink/broken_symlink internalError/fs ━━━━━━━━━━━━━━━━━━━━
! Dereferenced symlink
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ no files were processed in the specified paths.
# Emitted Messages

```block
<TEMP_DIR>/rome_test_infinite_symlink_exapansion/prefix internalError/fs ━━━━━━━━━━
<TEMP_DIR>/rome_test_infinite_symlink_exapansion/prefix internalError/fs ━━━━━━━━━━━━━━━━━━━━
! Infinite symlink expansion
Expand All @@ -21,7 +21,7 @@ no files were processed in the specified paths.
```

```block
<TEMP_DIR>/rome_test_infinite_symlink_exapansion/prefix internalError/fs ━━━━━━━━━━
<TEMP_DIR>/rome_test_infinite_symlink_exapansion/prefix internalError/fs ━━━━━━━━━━━━━━━━━━━━
! Infinite symlink expansion
Expand Down

0 comments on commit a0c84ce

Please sign in to comment.