feat(check): java public-class ⇄ file-name mismatch — layout finding with a ready jmove mv repair
- parser::java::class_name: exactly-one-public-top-level-type rule
(package-info/module-info and 0-or-2-public files skipped)
- check gains name_mismatches[] (JSON, omitted when clean) + human lines;
exit 2 covers both kinds; fix engine untouched by design — a file rename
is not a byte edit, and mv keeps the FQN so no imports change
- output split into output/{mod,check} to stay under the 250-line rule
- e2e: reports Bad.java, stays quiet on Good.java, suggested rename makes
check pass and preserves the file bytes
This commit is contained in:
parent
c0b06efe57
commit
f8004e669b
12 changed files with 334 additions and 80 deletions
43
tests/cli_name_check.rs
Normal file
43
tests/cli_name_check.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//! `jmove check` finds Java files whose public type is misnamed, and the
|
||||
//! suggested `jmove mv` repairs the layout.
|
||||
|
||||
mod common;
|
||||
|
||||
use common::{copy_fixture, in_root, jmove, read};
|
||||
use predicates::prelude::*;
|
||||
|
||||
const BAD: &str = "src/main/java/com/example/Bad.java";
|
||||
|
||||
#[test]
|
||||
fn check_reports_misnamed_public_class_and_clean_files_stay_quiet() {
|
||||
let tmp = copy_fixture("java", "mismatch");
|
||||
jmove(&tmp, &["check"])
|
||||
.code(2)
|
||||
.stdout(
|
||||
predicate::str::contains(
|
||||
"src/main/java/com/example/Bad.java:3: public class 'Wrong' must live in 'src/main/java/com/example/Wrong.java'",
|
||||
)
|
||||
.and(predicate::str::contains("Good.java").not()),
|
||||
);
|
||||
jmove(&tmp, &["check", "--json"])
|
||||
.code(2)
|
||||
.stdout(
|
||||
predicate::str::contains("\"name_mismatches\"")
|
||||
.and(predicate::str::contains("\"public_class\": \"Wrong\""))
|
||||
.and(predicate::str::contains(
|
||||
"\"rename\": \"jmove mv 'src/main/java/com/example/Bad.java' 'src/main/java/com/example/Wrong.java'\"",
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn running_the_suggested_rename_makes_check_pass() {
|
||||
let tmp = copy_fixture("java", "mismatch");
|
||||
jmove(&tmp, &["mv", BAD, "src/main/java/com/example/Wrong.java"]).success();
|
||||
let moved = read(&in_root(tmp.path(), "src/main/java/com/example/Wrong.java"));
|
||||
assert!(moved.contains("public class Wrong {}"), "{moved}");
|
||||
assert!(moved.contains("package com.example;"), "{moved}");
|
||||
jmove(&tmp, &["check"])
|
||||
.success()
|
||||
.stdout(predicate::str::contains("no findings"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue