Skip to content

Commit 55fbf5d

Browse files
aschemanclaude
andcommitted
Add test coverage for .htm files and fix README
Add tests to verify both .html and .htm files are discovered when sourceDocuments is auto-populated from sourceDir. - Maven plugin: Test verifies 3 files (.htm, .html, nested .htm) - Gradle plugin: Test verifies same file discovery pattern - Both tests confirm recursive directory scanning works for .htm - Fix Maven README: Use correct <sourceDocument> element name - All tests pass with no regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 34f94f1 commit 55fbf5d

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

htmlSanityCheck-gradle-plugin/src/test/groovy/org/aim42/htmlsanitycheck/gradle/HtmlSanityCheckTaskSpec.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,32 @@ class HtmlSanityCheckTaskSpec extends HtmlSanityCheckBaseSpec {
6262
e.message.contains("Your build configuration included 'failOnErrors=true', and 1 error(s) were found on all checked pages.")
6363
}
6464

65+
def "should include .htm files when auto-populating sourceDocuments"() {
66+
given:
67+
// Create .htm file
68+
def htmFile = new File(sourceDir, "document.htm")
69+
htmFile << VALID_HTML
70+
71+
// Create .html file
72+
htmlFile << VALID_HTML
73+
74+
// Create subdirectory with .htm file
75+
def subDir = new File(sourceDir, "docs")
76+
subDir.mkdirs()
77+
def nestedHtmFile = new File(subDir, "nested.htm")
78+
nestedHtmFile << VALID_HTML
79+
80+
when:
81+
task.setSourceDir(testProjectDir.root)
82+
83+
then:
84+
task.sourceDocuments != null
85+
// Verify that sourceDocuments includes both .html and .htm files
86+
def fileNames = task.sourceDocuments.files.collect { it.name }
87+
fileNames.contains("test.html")
88+
fileNames.contains("document.htm")
89+
fileNames.contains("nested.htm")
90+
task.sourceDocuments.files.size() == 3
91+
}
92+
6593
}

htmlSanityCheck-maven-plugin/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Use the following snippet inside a Maven build file:
4141
</executions>
4242
<configuration>
4343
<sourceDocuments>
44-
<file>src/file-to-test.html</file> <2>
44+
<sourceDocument>src/file-to-test.html</sourceDocument> <2>
4545
</sourceDocuments>
4646
<sourceDir>src</sourceDir> <3>
4747
</configuration>

htmlSanityCheck-maven-plugin/src/test/java/org/aim42/htmlsanitycheck/maven/HtmlSanityCheckMojoTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,55 @@ void executeWithOnlySourceDir_ShouldSucceed() throws IOException, MojoExecutionE
226226
deleteDirectory(resultDir.toFile());
227227
}
228228

229+
@Test
230+
void executeWithOnlySourceDir_ShouldIncludeHtmFiles() throws IOException, MojoExecutionException {
231+
// Setup: Create temp directories
232+
Path junitDir = Files.createTempDirectory("MojoJunit");
233+
Path resultDir = Files.createTempDirectory("MojoResult");
234+
Path sourceDir = Files.createTempDirectory("MojoSource");
235+
236+
// Create .htm file in root
237+
File rootHtmFile = new File(sourceDir.toFile(), "document.htm");
238+
Files.write(rootHtmFile.toPath(), VALID_HTML.getBytes(StandardCharsets.UTF_8));
239+
240+
// Create .html file for comparison
241+
File rootHtmlFile = new File(sourceDir.toFile(), "page.html");
242+
Files.write(rootHtmlFile.toPath(), VALID_HTML.getBytes(StandardCharsets.UTF_8));
243+
244+
// Create subdirectory with .htm file
245+
File subDir = new File(sourceDir.toFile(), "docs");
246+
boolean mkdirSuccess = subDir.mkdirs();
247+
Assertions.assertThat(mkdirSuccess).isTrue();
248+
File nestedHtmFile = new File(subDir, "nested.htm");
249+
Files.write(nestedHtmFile.toPath(), VALID_HTML.getBytes(StandardCharsets.UTF_8));
250+
251+
// Create Mojo and set only sourceDir field
252+
HtmlSanityCheckMojo mojo = new TestableHtmlSanityCheckMojo(
253+
sourceDir.toFile(),
254+
null, // sourceDocuments explicitly NOT set
255+
resultDir.toFile(),
256+
junitDir.toFile()
257+
);
258+
259+
// Get the configuration to verify sourceDocuments includes .htm files
260+
Configuration config = mojo.setupConfiguration();
261+
262+
// Verify that both .html and .htm files are discovered
263+
Assertions.assertThat(config.getSourceDocuments()).isNotNull();
264+
Assertions.assertThat(config.getSourceDocuments()).hasSize(3);
265+
Assertions.assertThat(config.getSourceDocuments())
266+
.extracting(File::getName)
267+
.containsExactlyInAnyOrder("document.htm", "page.html", "nested.htm");
268+
269+
// Execute should succeed with both file types
270+
mojo.execute();
271+
272+
// Clean up
273+
deleteDirectory(sourceDir.toFile());
274+
deleteDirectory(junitDir.toFile());
275+
deleteDirectory(resultDir.toFile());
276+
}
277+
229278
/**
230279
* Helper class to allow setting private fields for testing
231280
*/

0 commit comments

Comments
 (0)