Skip to content

Commit 85f0725

Browse files
Add more tests (#5)
1 parent 9b08b76 commit 85f0725

File tree

6 files changed

+1501
-89
lines changed

6 files changed

+1501
-89
lines changed

.github/codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ coverage:
88
patch:
99
default:
1010
enabled: false
11+
12+
ignore:
13+
- "crates/action-format/**/*"

crates/action-format/src/main.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,22 @@ fn main() -> ExitCode {
4343
match run(&cli, printer) {
4444
Ok(status) => status.into(),
4545
Err(err) => {
46-
let _ = writeln!(printer.stderr(), "{}: {}", "error".red().bold(), err);
46+
#[allow(clippy::print_stderr)]
47+
{
48+
let mut causes = err.chain();
49+
eprintln!(
50+
"{}: {}",
51+
"error".red().bold(),
52+
causes.next().unwrap().to_string().trim()
53+
);
54+
for cause in causes {
55+
eprintln!(
56+
" {}: {}",
57+
"Caused by".red().bold(),
58+
cause.to_string().trim()
59+
);
60+
}
61+
}
4762
ExitStatus::Error.into()
4863
}
4964
}
@@ -60,11 +75,13 @@ fn run(cli: &Cli, printer: Printer) -> Result<ExitStatus> {
6075
let mut any_changed = false;
6176
let mut any_error = false;
6277

63-
for entry in walkdir::WalkDir::new(workflows_path)
78+
let walker = walkdir::WalkDir::new(workflows_path)
79+
.sort_by_file_name()
6480
.into_iter()
65-
.filter_map(std::result::Result::ok)
66-
.filter(|e| is_workflow_file(e.path()))
67-
{
81+
.filter_map(Result::ok)
82+
.filter(|e| is_workflow_file(e.path()));
83+
84+
for entry in walker {
6885
match process_file(entry.path(), &config, cli, printer) {
6986
Ok(changed) => any_changed |= changed,
7087
Err(e) => {
@@ -121,16 +138,18 @@ fn process_file(
121138

122139
if cli.diff {
123140
print_diff(path, &content, &formatted, printer);
141+
return Ok(true);
124142
}
125143

144+
fs_err::write(path, &formatted)?;
145+
126146
let _ = writeln!(
127147
printer.stdout(),
128148
"{}: {}",
129149
"Reformatted".green(),
130150
path.display()
131151
);
132152

133-
fs_err::write(path, &formatted)?;
134153
Ok(true)
135154
}
136155

crates/action-format/tests/it/.format.rs.pending-snap

Lines changed: 0 additions & 36 deletions
This file was deleted.

crates/action-format/tests/it/common/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ impl TestContext {
8383
}
8484

8585
/// Create an action-format command for testing.
86-
#[allow(clippy::unused_self)]
8786
pub fn command(&self) -> Command {
8887
let mut command = Command::new(get_bin());
8988
command.current_dir(self.root.path());
89+
command.env("NO_COLOR", "1");
9090
command
9191
}
9292
}
@@ -101,18 +101,18 @@ pub fn get_bin() -> PathBuf {
101101
PathBuf::from(env!("CARGO_BIN_EXE_action-format"))
102102
}
103103

104+
/// Common filters for snapshot testing.
104105
pub static INSTA_FILTERS: &[(&str, &str)] = &[
106+
// Normalize Windows line endings
105107
(r"\r\n", "\n"),
108+
// Normalize Windows paths
106109
(r"\\", "/"),
110+
// Rewrite Windows output to Unix output
107111
(r"\\([\w\d]|\.)", "/$1"),
108-
(r"action-format\.exe", "action-format"),
109-
(
110-
r"action-format(-.*)? \d+\.\d+\.\d+(-(alpha|beta|rc)\.\d+)?",
111-
r"action-format [VERSION]",
112-
),
112+
(r"seal\.exe", "seal"),
113+
// Strip ANSI color codes (match ESC character using character class)
113114
(r"[\x1b]\[[0-9;]*m", ""),
114-
// Normalize .github/workflows path
115-
(r"\.github/workflows/", ""),
115+
(r"\d+(?:;\d+)*m", ""),
116116
];
117117

118118
pub fn apply_filters<T: AsRef<str>>(mut snapshot: String, filters: impl AsRef<[(T, T)]>) -> String {

0 commit comments

Comments
 (0)