Skip to content

Commit adaaef9

Browse files
committed
check for duplicate expectation files
1 parent ce5be9e commit adaaef9

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2002-2009 Andy Clark, Marc Guillemot
3+
* Copyright (c) 2017-2024 Ronald Brill
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.htmlunit.cyberneko;
17+
18+
import static org.junit.jupiter.api.Assertions.fail;
19+
20+
import java.io.File;
21+
import java.io.IOException;
22+
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.MethodSource;
25+
26+
/**
27+
* This test checks for duplicate expectation files.
28+
*
29+
* @author Ronald Brill
30+
*/
31+
public class CanonicalDuplicateFileTest extends AbstractCanonicalTest {
32+
33+
@ParameterizedTest
34+
@MethodSource("testFiles")
35+
public void runTest(final File dataFile) throws Exception {
36+
test(dataFile);
37+
}
38+
39+
private static void test(final File dataFile) throws Exception {
40+
final File canonicalFile = new File(dataFile.getParentFile(), dataFile.getName() + ".canonical");
41+
final File canonicalDomFile = new File(dataFile.getParentFile(), dataFile.getName() + ".canonical-dom");
42+
43+
// CanonicalCustomSAXParserTest
44+
File candidate = new File(dataFile.getParentFile(), dataFile.getName() + ".canonical-sax-cust");
45+
assertNotSame(candidate, canonicalFile);
46+
47+
// CanonicalDomFragmentTest
48+
candidate = new File(dataFile.getParentFile(), dataFile.getName() + ".canonical-frg");
49+
assertNotSame(candidate, canonicalFile);
50+
assertNotSame(candidate, canonicalDomFile);
51+
52+
// CanonicalDomHtmlDocumentTest
53+
candidate = new File(dataFile.getParentFile(), dataFile.getName() + ".canonical-domhtml");
54+
assertNotSame(candidate, canonicalFile);
55+
assertNotSame(candidate, canonicalDomFile);
56+
57+
// CanonicalDomTest
58+
candidate = new File(dataFile.getParentFile(), dataFile.getName() + ".canonical-dom");
59+
assertNotSame(candidate, canonicalFile);
60+
61+
// CanonicalHtmlWriterTest
62+
63+
// CanonicalSAXTest
64+
candidate = new File(dataFile.getParentFile(), dataFile.getName() + ".canonical-sax");
65+
assertNotSame(candidate, canonicalFile);
66+
67+
// CanonicalTest
68+
69+
// CanonicalXNITest
70+
}
71+
72+
private static void assertNotSame(final File candidate, final File reference) throws IOException {
73+
if (reference.exists() && candidate.exists()) {
74+
final String referenceContent = getCanonical(reference);
75+
final String candidateContent = getCanonical(candidate);
76+
if (referenceContent.equals(candidateContent)) {
77+
fail("File '" + candidate.getAbsolutePath()
78+
+ "' is obsolete (has the same content as the fallback file '"
79+
+ reference.getAbsolutePath() + ".");
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)