|
7 | 7 |
|
8 | 8 | import java.io.File;
|
9 | 9 | import java.nio.charset.Charset;
|
| 10 | +import java.time.LocalDate; |
| 11 | +import java.time.format.DateTimeFormatter; |
10 | 12 | import java.util.Collection;
|
11 | 13 | import java.util.LinkedList;
|
12 | 14 |
|
|
23 | 25 | public class TxtWorkAroundRegression {
|
24 | 26 | final static private String ROOTFOLDER = "E:\\arduinoTxt-Backup-2021-08-19";
|
25 | 27 | 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; |
26 | 32 |
|
27 | 33 | public TxtWorkAroundRegression(String pathName) {
|
28 | 34 | myPath = new Path(pathName);
|
@@ -105,21 +111,47 @@ public void platformTxt() throws Exception {
|
105 | 111 | System.out.println("file does not exists " + inputFile);
|
106 | 112 | assumeFalse(true);// skip the test
|
107 | 113 | }
|
108 |
| - if (!expectedFile.exists()) { |
109 |
| - System.out.println("file does not exists " + expectedFile); |
110 |
| - assumeFalse(true);// skip the test |
111 |
| - } |
112 | 114 | String input = FileUtils.readFileToString(inputFile, Charset.defaultCharset());
|
113 | 115 | 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 | + } |
123 | 155 | }
|
124 | 156 |
|
125 | 157 | }
|
|
0 commit comments