mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-29 03:27:44 +00:00
test: more tests
This commit is contained in:
parent
6db8876433
commit
7da44e0943
6 changed files with 152 additions and 12 deletions
|
@ -92,8 +92,8 @@
|
|||
cargo-license
|
||||
cargo-tarpaulin
|
||||
jq
|
||||
inputs.fenix.packages."x86_64-linux".stable.toolchain
|
||||
inputs.fenix.packages."x86_64-linux".latest.rustfmt
|
||||
inputs.fenix.packages."x86_64-linux".stable.toolchain
|
||||
linuxPackages_latest.perf
|
||||
nodejs
|
||||
nodePackages.prettier
|
||||
|
|
|
@ -21,5 +21,5 @@ struct_field_align_threshold = 999
|
|||
unstable_features = true
|
||||
use_field_init_shorthand = true
|
||||
use_small_heuristics = "Max"
|
||||
version = "Two"
|
||||
style_edition = "2021"
|
||||
wrap_comments = true
|
||||
|
|
|
@ -34,7 +34,11 @@ pub(crate) fn build(
|
|||
build_step(&mut builder, build_ctx, &crate::builder::Step::Format(element));
|
||||
|
||||
if build_ctx.force_wide {
|
||||
if build_ctx.force_wide_success { Some(builder.finish()) } else { None }
|
||||
if build_ctx.force_wide_success {
|
||||
Some(builder.finish())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
Some(builder.finish())
|
||||
}
|
||||
|
|
|
@ -22,7 +22,11 @@ impl Children {
|
|||
matches!(child.kind(), rnix::SyntaxKind::TOKEN_COMMENT)
|
||||
});
|
||||
|
||||
if has_comments { Some(build_ctx.pos_old.clone()) } else { None }
|
||||
if has_comments {
|
||||
Some(build_ctx.pos_old.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
for child in node.children_with_tokens() {
|
||||
|
|
|
@ -13,24 +13,41 @@ struct TestCase {
|
|||
const CASES: &[TestCase] = &[
|
||||
TestCase { args: &["--help"], stdin: None },
|
||||
TestCase { args: &["--version"], stdin: None },
|
||||
//
|
||||
TestCase { args: &[], stdin: None },
|
||||
// changed
|
||||
TestCase { args: &[], stdin: Some("[]") },
|
||||
TestCase { args: &["--quiet"], stdin: Some("[]") },
|
||||
TestCase { args: &["--quiet", "--quiet"], stdin: Some("[]") },
|
||||
// check unchanged
|
||||
TestCase { args: &["--check"], stdin: Some("[]\n") },
|
||||
TestCase { args: &["--check", "--quiet"], stdin: Some("[]\n") },
|
||||
TestCase { args: &["--check", "--quiet"], stdin: Some("[\t]") },
|
||||
TestCase { args: &["--check", "--quiet", "--quiet"], stdin: Some("[]\n") },
|
||||
// check changed
|
||||
TestCase { args: &["--check"], stdin: Some("[\t]") },
|
||||
TestCase { args: &["--check", "--quiet"], stdin: Some("[\t]") },
|
||||
TestCase { args: &["--check", "--quiet", "--quiet"], stdin: Some("[\t]") },
|
||||
// check error
|
||||
TestCase { args: &[], stdin: Some("[") },
|
||||
TestCase { args: &["--quiet"], stdin: Some("[") },
|
||||
TestCase { args: &["--quiet", "--quiet"], stdin: Some("[") },
|
||||
// nothing to format
|
||||
TestCase { args: &[".", "--exclude", "."], stdin: None },
|
||||
TestCase { args: &[".", "--exclude", ".", "--quiet"], stdin: None },
|
||||
TestCase {
|
||||
args: &["--exclude", ".", "--quiet", "--quiet", "--", "."],
|
||||
stdin: None,
|
||||
},
|
||||
//
|
||||
TestCase { args: &["--check", "tests/inputs/changed.nix"], stdin: None },
|
||||
TestCase {
|
||||
args: &["--check", "tests/inputs/changed.nix", "--quiet"],
|
||||
stdin: None,
|
||||
},
|
||||
TestCase {
|
||||
args: &["-c", "tests/inputs/changed.nix", "-e", "tests/changed.nix"],
|
||||
stdin: None,
|
||||
},
|
||||
TestCase {
|
||||
args: &[
|
||||
"-c",
|
||||
|
@ -45,6 +62,7 @@ const CASES: &[TestCase] = &[
|
|||
args: &["--check", "tests/inputs/changed.nix", "-qq"],
|
||||
stdin: None,
|
||||
},
|
||||
TestCase { args: &["-c", "tests/inputs/unchanged.nix"], stdin: None },
|
||||
TestCase {
|
||||
args: &["--check", "tests/inputs/unchanged.nix", "-q"],
|
||||
stdin: None,
|
||||
|
@ -53,6 +71,7 @@ const CASES: &[TestCase] = &[
|
|||
args: &["--check", "tests/inputs/unchanged.nix", "-qq"],
|
||||
stdin: None,
|
||||
},
|
||||
TestCase { args: &["--check", "tests/inputs/error.nix"], stdin: None },
|
||||
TestCase {
|
||||
args: &["--check", "tests/inputs/error.nix", "-q"],
|
||||
stdin: None,
|
||||
|
|
|
@ -62,6 +62,21 @@ stderr:
|
|||
|
||||
exit code: Some(1)
|
||||
===
|
||||
args: []
|
||||
stdin: "[]"
|
||||
stdout:
|
||||
[]
|
||||
|
||||
stderr:
|
||||
Formatting stdin.
|
||||
Use --help to see all command line options.
|
||||
use --quiet to suppress this and other messages.
|
||||
|
||||
Success! 1 file was formatted.
|
||||
|
||||
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--quiet"]
|
||||
stdin: "[]"
|
||||
stdout:
|
||||
|
@ -74,6 +89,21 @@ stdin: "[]"
|
|||
stdout:
|
||||
[]
|
||||
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check"]
|
||||
stdin: "[]\n"
|
||||
stdout:
|
||||
[]
|
||||
|
||||
stderr:
|
||||
Formatting stdin.
|
||||
Use --help to see all command line options.
|
||||
use --quiet to suppress this and other messages.
|
||||
|
||||
Congratulations! Your code complies with the Alejandra style.
|
||||
|
||||
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check", "--quiet"]
|
||||
|
@ -83,6 +113,27 @@ stdout:
|
|||
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check", "--quiet", "--quiet"]
|
||||
stdin: "[]\n"
|
||||
stdout:
|
||||
[]
|
||||
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check"]
|
||||
stdin: "[\t]"
|
||||
stdout:
|
||||
[]
|
||||
|
||||
stderr:
|
||||
Formatting stdin.
|
||||
Use --help to see all command line options.
|
||||
use --quiet to suppress this and other messages.
|
||||
|
||||
Alert! 1 file requires formatting.
|
||||
|
||||
exit code: Some(2)
|
||||
===
|
||||
args: ["--check", "--quiet"]
|
||||
stdin: "[\t]"
|
||||
stdout:
|
||||
|
@ -91,19 +142,27 @@ stdout:
|
|||
exit code: Some(2)
|
||||
===
|
||||
args: ["--check", "--quiet", "--quiet"]
|
||||
stdin: "[]\n"
|
||||
stdout:
|
||||
[]
|
||||
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check", "--quiet", "--quiet"]
|
||||
stdin: "[\t]"
|
||||
stdout:
|
||||
[]
|
||||
|
||||
exit code: Some(2)
|
||||
===
|
||||
args: []
|
||||
stdin: "["
|
||||
stdout:
|
||||
[
|
||||
|
||||
stderr:
|
||||
Formatting stdin.
|
||||
Use --help to see all command line options.
|
||||
use --quiet to suppress this and other messages.
|
||||
|
||||
Failed! 1 error found at:
|
||||
- <anonymous file on stdin>: unexpected end of file
|
||||
|
||||
exit code: Some(1)
|
||||
===
|
||||
args: ["--quiet"]
|
||||
stdin: "["
|
||||
stdout:
|
||||
|
@ -123,13 +182,47 @@ stdout:
|
|||
|
||||
exit code: Some(1)
|
||||
===
|
||||
args: [".", "--exclude", "."]
|
||||
stderr:
|
||||
Checking style in 0 files using 4 threads.
|
||||
|
||||
|
||||
Congratulations! Your code complies with the Alejandra style.
|
||||
|
||||
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: [".", "--exclude", ".", "--quiet"]
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--exclude", ".", "--quiet", "--quiet", "--", "."]
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check", "tests/inputs/changed.nix"]
|
||||
stdout:
|
||||
Requires formatting: tests/inputs/changed.nix
|
||||
|
||||
stderr:
|
||||
Checking style in 1 file using 4 threads.
|
||||
|
||||
|
||||
Alert! 1 file requires formatting.
|
||||
|
||||
exit code: Some(2)
|
||||
===
|
||||
args: ["--check", "tests/inputs/changed.nix", "--quiet"]
|
||||
exit code: Some(2)
|
||||
===
|
||||
args: ["-c", "tests/inputs/changed.nix", "-e", "tests/changed.nix"]
|
||||
stdout:
|
||||
Requires formatting: tests/inputs/changed.nix
|
||||
|
||||
stderr:
|
||||
Checking style in 1 file using 4 threads.
|
||||
|
||||
|
||||
Alert! 1 file requires formatting.
|
||||
|
||||
exit code: Some(2)
|
||||
===
|
||||
args: ["-c", "tests/inputs/changed.nix", "-q", "-e", "tests/changed.nix"]
|
||||
|
@ -138,12 +231,32 @@ exit code: Some(2)
|
|||
args: ["--check", "tests/inputs/changed.nix", "-qq"]
|
||||
exit code: Some(2)
|
||||
===
|
||||
args: ["-c", "tests/inputs/unchanged.nix"]
|
||||
stderr:
|
||||
Checking style in 1 file using 4 threads.
|
||||
|
||||
|
||||
Congratulations! Your code complies with the Alejandra style.
|
||||
|
||||
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check", "tests/inputs/unchanged.nix", "-q"]
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check", "tests/inputs/unchanged.nix", "-qq"]
|
||||
exit code: Some(0)
|
||||
===
|
||||
args: ["--check", "tests/inputs/error.nix"]
|
||||
stderr:
|
||||
Checking style in 1 file using 4 threads.
|
||||
|
||||
|
||||
Failed! 1 error found at:
|
||||
- tests/inputs/error.nix: unexpected end of file
|
||||
|
||||
exit code: Some(1)
|
||||
===
|
||||
args: ["--check", "tests/inputs/error.nix", "-q"]
|
||||
stderr:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue