Skip to content

Commit 672f6e2

Browse files
author
jantje
committed
#1476 changed the test so I can compare 2 code sets
1 parent 70ca7cf commit 672f6e2

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

io.sloeber.tests/src/io/sloeber/junit/TxtWorkAroundRegression.java

+45-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import java.io.File;
99
import java.nio.charset.Charset;
10+
import java.time.LocalDate;
11+
import java.time.format.DateTimeFormatter;
1012
import java.util.Collection;
1113
import java.util.LinkedList;
1214

@@ -23,6 +25,10 @@
2325
public class TxtWorkAroundRegression {
2426
final static private String ROOTFOLDER = "E:\\arduinoTxt-Backup-2021-08-19";
2527
private Path myPath;
28+
private Path myOutputPath = new Path(
29+
"E:\\test\\workaround\\" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-DD")));
30+
private boolean comparePlarformFiles = false;
31+
static private int differenceCount = 0;
2632

2733
public TxtWorkAroundRegression(String pathName) {
2834
myPath = new Path(pathName);
@@ -105,21 +111,47 @@ public void platformTxt() throws Exception {
105111
System.out.println("file does not exists " + inputFile);
106112
assumeFalse(true);// skip the test
107113
}
108-
if (!expectedFile.exists()) {
109-
System.out.println("file does not exists " + expectedFile);
110-
assumeFalse(true);// skip the test
111-
}
112114
String input = FileUtils.readFileToString(inputFile, Charset.defaultCharset());
113115
input = input.replace("\r\n", "\n");
114-
String expected = FileUtils.readFileToString(expectedFile, Charset.defaultCharset());
115-
String actual = platformApplyWorkArounds(input, inputFile);
116-
String cleanedExpected = clean(expected);
117-
String cleanedActual = clean(actual);
118-
String difference = StringUtils.difference(cleanedExpected, cleanedActual);
119-
if (!cleanedExpected.equals(cleanedActual)) {
120-
System.err.println("ERROR for " + inputFile);
121-
System.err.println(difference);
122-
fail(difference.substring(0, 20));
116+
String currentWorkAround = platformApplyWorkArounds(input, inputFile);
117+
String cleanedCurrentWorkAround = clean(currentWorkAround);
118+
119+
if (comparePlarformFiles) {
120+
//compare the Sloeber generated workaround file content to the content of the file on disk
121+
if (!expectedFile.exists()) {
122+
System.out.println("file does not exists " + expectedFile);
123+
assumeFalse(true);// skip the test
124+
}
125+
126+
String expected = FileUtils.readFileToString(expectedFile, Charset.defaultCharset());
127+
String cleanedExpected = clean(expected);
128+
129+
String difference = StringUtils.difference(cleanedExpected, cleanedCurrentWorkAround);
130+
if (!cleanedExpected.equals(cleanedCurrentWorkAround)) {
131+
System.err.println("ERROR for " + inputFile);
132+
System.err.println(difference);
133+
fail(difference.substring(0, 20));
134+
}
135+
} else {
136+
//compare the Sloeber generated workaround file content to the content generated by other code
137+
//the idea is to compare the current code to the old code
138+
//this because it is hard to update the files on disk
139+
String oldWorkAround = io.sloeber.core.txt.WorkAroundOrg.platformApplyWorkArounds(input, inputFile);
140+
String cleanedOldWorkAround = clean(oldWorkAround);
141+
142+
if (!cleanedOldWorkAround.equals(cleanedCurrentWorkAround)) {
143+
differenceCount += 1;
144+
String prefix = String.format("%04d", differenceCount) + "_";
145+
System.err.println("ERROR for " + inputFile);
146+
String difference = StringUtils.difference(cleanedCurrentWorkAround, cleanedOldWorkAround);
147+
System.err.println(difference);
148+
File current = myOutputPath.append(prefix + "CurrentWorkAround.txt").toFile();
149+
File old = myOutputPath.append(prefix + "OldWorkAround.txt").toFile();
150+
FileUtils.writeStringToFile(current, cleanedCurrentWorkAround, Charset.defaultCharset());
151+
FileUtils.writeStringToFile(old, cleanedOldWorkAround, Charset.defaultCharset());
152+
153+
fail(difference.substring(0, 20));
154+
}
123155
}
124156

125157
}

0 commit comments

Comments
 (0)