Skip to content

Commit e2d2998

Browse files
Pieter12345cmaglie
authored andcommitted
Fix MergeSketchWithUploaderText failing under Windows
When having "autocrlf=input" (as described in the Building Arduino guide), the `.hex` files used in the test will be a different size due to the test expecting `\n` and git cloning as `\r\n`. This commit fixes this issue by removing cariage returns before running the test.
1 parent 6d9dd97 commit e2d2998

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Diff for: app/test/cc/arduino/packages/uploaders/MergeSketchWithUploaderTest.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,29 @@
3535
import processing.app.helpers.FileUtils;
3636

3737
import java.io.File;
38+
import java.net.URLDecoder;
39+
import java.nio.charset.StandardCharsets;
40+
import java.nio.file.Files;
41+
import java.util.List;
3842

3943
import static org.junit.Assert.assertEquals;
4044

4145
public class MergeSketchWithUploaderTest {
4246

4347
private File sketch;
48+
private File bootloader;
4449

4550
@Before
4651
public void setup() throws Exception {
47-
File originalSketch = new File(MergeSketchWithUploaderTest.class.getResource("/sketch.hex").getFile());
52+
File originalSketch = getResourceFile("/sketch.hex");
4853
sketch = new File(System.getProperty("java.io.tmpdir"), "sketch.hex");
4954
FileUtils.copyFile(originalSketch, sketch);
55+
removeCariageReturns(sketch);
56+
57+
File originalBootloader = getResourceFile("/optiboot_atmega328.hex");
58+
bootloader = new File(System.getProperty("java.io.tmpdir"), "optiboot_atmega328.hex");
59+
FileUtils.copyFile(originalBootloader, bootloader);
60+
removeCariageReturns(bootloader);
5061
}
5162

5263
@After
@@ -57,11 +68,24 @@ public void removeTmpFile() {
5768
@Test
5869
public void shouldMergeWithOptiboot() throws Exception {
5970
assertEquals(11720, sketch.length());
71+
assertEquals(1432, bootloader.length());
6072

61-
File bootloader = new File(MergeSketchWithUploaderTest.class.getResource("/optiboot_atmega328.hex").getFile());
73+
File bootloader = getResourceFile("/optiboot_atmega328.hex");
6274
new MergeSketchWithBooloader().merge(sketch, bootloader);
6375
assertEquals(13140, sketch.length());
6476
}
6577

78+
private static File getResourceFile(String resourcePath) throws Exception {
79+
return new File(URLDecoder.decode(
80+
MergeSketchWithUploaderTest.class.getResource(resourcePath).getFile(), "UTF-8"));
81+
}
6682

83+
private static void removeCariageReturns(File file) throws Exception {
84+
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
85+
StringBuilder contentBuilder = new StringBuilder();
86+
for(String line : lines) {
87+
contentBuilder.append(line).append('\n');
88+
}
89+
Files.write(file.toPath(), contentBuilder.toString().getBytes(StandardCharsets.UTF_8));
90+
}
6791
}

0 commit comments

Comments
 (0)