Skip to content

Commit

Permalink
fix unit tests #1593
Browse files Browse the repository at this point in the history
  • Loading branch information
jantje committed Nov 26, 2023
1 parent 56e9862 commit 17f5561
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion io.sloeber.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Require-Bundle: org.eclipse.cdt.managedbuilder.core,
org.eclipse.ui.console,
org.eclipse.debug.core,
org.eclipse.core.variables,
org.apache.commons.io,
org.apache.commons.commons-io,
org.apache.commons.compress
Export-Package: cc.arduino.packages;x-internal:=true,
cc.arduino.packages.discoverers;x-internal:=true,
Expand Down
6 changes: 3 additions & 3 deletions io.sloeber.product/sloeber.target
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<unit id="org.eclipse.ecf.core.feature.group" version="0.0.0"/>
<unit id="org.eclipse.wildwebdeveloper.feature.feature.group" version="0.0.0"/>
</location>
<location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" label="DirectFromMaven" missingManifest="error" type="Maven">
<location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" label="DirectFromMaven" missingManifest="error" type="Maven">
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -41,13 +41,13 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.23.0</version>
<version>1.25.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
<version>2.15.0</version>
<type>jar</type>
</dependency>
</dependencies>
Expand Down
33 changes: 15 additions & 18 deletions io.sloeber.tests/src/io/sloeber/core/Shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,25 +351,22 @@ private static void extractFile(ZipInputStream zipIn, String filePath) throws IO
* make the strings equal.
*/
public static String[] difference(String a, String b) {
return diffHelper(a, b, new HashMap<>());
}

@SuppressWarnings("boxing")
private static String[] diffHelper(String a, String b, Map<Long, String[]> lookup) {
return lookup.computeIfAbsent(((long) a.length()) << 32 | b.length(), k -> {
if (a.isEmpty() || b.isEmpty()) {
return new String[] { a, b };
} else if (a.charAt(0) == b.charAt(0)) {
return diffHelper(a.substring(1), b.substring(1), lookup);
int startDiff = 1;
while (a.substring(0, startDiff).equals(b.substring(0, startDiff))) {
startDiff++;
}
int endDiff = startDiff + 20;
if (startDiff > 10) {
int nl = a.substring(0, startDiff).lastIndexOf('\n');
if (nl != -1) {
startDiff = nl;
} else {
String[] aa = diffHelper(a.substring(1), b, lookup);
String[] bb = diffHelper(a, b.substring(1), lookup);
if (aa[0].length() + aa[1].length() < bb[0].length() + bb[1].length()) {
return new String[] { a.charAt(0) + aa[0], aa[1] };
}
return new String[] { bb[0], b.charAt(0) + bb[1] };
startDiff = startDiff - 5;
}
});
} else {
startDiff = 0;
}
return new String[] { a.substring(startDiff, endDiff), b.substring(startDiff, endDiff) };
}
//end of copied from https://stackoverflow.com/questions/18344721/extract-the-difference-between-two-strings-in-java

}
10 changes: 9 additions & 1 deletion io.sloeber.tests/src/io/sloeber/junit/AllJUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

/*
* these junit tests need to be run as a junit plugin
*
*
* TxtWorkAroundRegression.class is not included as it needs a special setup to run
* The special setup is a arduinoplugin folder with "old" sloeber.txt files so the differences can be spotted
*/

@RunWith(Suite.class)
@SuiteClasses({ TestPlatformWorkAround.class, TestSerialPlotterFilter.class, TestTxtFile.class, TestWorkAround.class,
TxtWorkAroundRegression.class, TestVersionCompare.class })
TestVersionCompare.class })
public class AllJUnitTests {
//no need for code here
}

0 comments on commit 17f5561

Please sign in to comment.