Skip to content

Commit 298a0bf

Browse files
author
jantje
committed
Nicer names for junit tests
Also changed the examples test to work both with uno and leonardo Added a list of examples that not work
1 parent b32a6d2 commit 298a0bf

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

io.sloeber.core/src/jUnit/CreateAndCompile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.junit.Test;
1717
import org.junit.runner.RunWith;
1818
import org.junit.runners.Parameterized;
19+
import org.junit.runners.Parameterized.Parameters;
1920

2021
import io.sloeber.core.api.BoardDescriptor;
2122
import io.sloeber.core.api.BoardsManager;
@@ -49,7 +50,7 @@ public CreateAndCompile(String jsonFileName, String packageName, String platform
4950
}
5051

5152
@SuppressWarnings("rawtypes")
52-
@Parameterized.Parameters
53+
@Parameters(name = "{index}: {0} {1} {2} {3} {4}")
5354
public static Collection boards() {
5455
return Arrays.asList(new Object[][] {
5556

io.sloeber.core/src/jUnit/CreateAndCompileExamples.java

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
2323
import org.junit.runners.Parameterized;
24+
import org.junit.runners.Parameterized.Parameters;
2425

2526
import io.sloeber.core.api.BoardDescriptor;
2627
import io.sloeber.core.api.BoardsManager;
@@ -33,30 +34,79 @@
3334
public class CreateAndCompileExamples {
3435
private static int mCounter = 0;
3536
private CodeDescriptor myCodeDescriptor;
37+
private BoardDescriptor myBoardid;
3638

37-
public CreateAndCompileExamples(CodeDescriptor codeDescriptor) {
39+
public CreateAndCompileExamples(String name, BoardDescriptor boardid, CodeDescriptor codeDescriptor) {
40+
this.myBoardid = boardid;
3841
this.myCodeDescriptor = codeDescriptor;
3942

4043
}
4144

4245
@SuppressWarnings("rawtypes")
43-
@Parameterized.Parameters
46+
@Parameters(name = "{index}: {0}")
4447
public static Collection examples() {
45-
LinkedList<CodeDescriptor> examples = new LinkedList<>();
48+
Map<String, String> myOptions = new HashMap<>();
49+
String[] lines = new String("").split("\n"); //$NON-NLS-1$
50+
for (String curLine : lines) {
51+
String[] values = curLine.split("=", 2); //$NON-NLS-1$
52+
if (values.length == 2) {
53+
myOptions.put(values[0], values[1]);
54+
}
55+
}
56+
BoardDescriptor leonardoBoardid = BoardsManager.getBoardID("package_index.json", "arduino",
57+
"Arduino AVR Boards", "leonardo", myOptions);
58+
if (leonardoBoardid == null) {
59+
fail("leonardo Board not found");
60+
return null;
61+
}
62+
BoardDescriptor unoBoardid = BoardsManager.getBoardID("package_index.json", "arduino", "Arduino AVR Boards",
63+
"uno", myOptions);
64+
if (unoBoardid == null) {
65+
fail("uno Board not found");
66+
return null;
67+
}
68+
69+
LinkedList<Object[]> examples = new LinkedList<>();
4670
TreeMap<String, IPath> exampleFolders = BoardsManager.getAllExamples(null);
4771
for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
4872
ArrayList<Path> paths = new ArrayList<>();
4973

5074
paths.add(new Path(curexample.getValue().toString()));
5175
CodeDescriptor codeDescriptor = CodeDescriptor.createExample(false, paths);
76+
if (isExampleOkForLeonardo(curexample.getKey())) {
77+
Object[] theData = new Object[] { "leonardo :" + curexample.getKey(), leonardoBoardid, codeDescriptor };
5278

53-
examples.add(codeDescriptor);
79+
examples.add(theData);
80+
}
81+
if (isExampleOkForUno(curexample.getKey())) {
82+
Object[] theData = new Object[] { "Uno :" + curexample.getKey(), unoBoardid, codeDescriptor };
83+
84+
examples.add(theData);
85+
}
5486
}
5587

5688
return examples;
5789

5890
}
5991

92+
private static boolean isExampleOkForUno(String key) {
93+
final String[] notOkForUno = { "Esploraexamples-Beginners-EsploraAccelerometer",
94+
"Esploraexamples-Beginners-EsploraBlink", "Esploraexamples-Beginners-EsploraJoystickMouse",
95+
"Esploraexamples-Beginners-EsploraLedShow", "Esploraexamples-Beginners-EsploraLedShow2" };
96+
if (key.startsWith("Esploraexamples"))
97+
return false;
98+
if (Arrays.asList(notOkForUno).contains(key))
99+
return false;
100+
return true; // default everything is fine
101+
}
102+
103+
private static boolean isExampleOkForLeonardo(String key) {
104+
final String[] notOkForLeonardo = { "Esploraexamples-Beginners-EsploraJoystickMouse" };
105+
if (Arrays.asList(notOkForLeonardo).contains(key))
106+
return false;
107+
return true; // default everything is fine
108+
}
109+
60110
/*
61111
* In new new installations (of the Sloeber development environment) the
62112
* installer job will trigger downloads These mmust have finished before we
@@ -76,24 +126,8 @@ public static void installAdditionalBoards() {
76126
}
77127

78128
@Test
79-
public void testLeonardo() {
80-
81-
Map<String, String> myOptions = new HashMap<>();
82-
String[] lines = new String("").split("\n"); //$NON-NLS-1$
83-
for (String curLine : lines) {
84-
String[] values = curLine.split("=", 2); //$NON-NLS-1$
85-
if (values.length == 2) {
86-
myOptions.put(values[0], values[1]);
87-
}
88-
}
89-
90-
BoardDescriptor boardid = BoardsManager.getBoardID("package_index.json", "arduino", "Arduino AVR Boards",
91-
"leonardo", myOptions);
92-
if (boardid == null) {
93-
fail("Uno Board not found");
94-
return;
95-
}
96-
BuildAndVerify(boardid, this.myCodeDescriptor);
129+
public void testExamples() {
130+
BuildAndVerify(this.myBoardid, this.myCodeDescriptor);
97131

98132
}
99133

0 commit comments

Comments
 (0)