Skip to content

Commit 39f396e

Browse files
committed
Added test to check preference saving from cmd line
See #6067
1 parent 674419a commit 39f396e

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

app/test/processing/app/CommandLineTest.java

+46-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
package processing.app;
3131

32-
import static org.junit.Assert.assertEquals;
32+
import static org.junit.Assert.*;
3333

3434
import java.io.File;
3535

@@ -38,6 +38,7 @@
3838
import org.junit.Test;
3939

4040
import processing.app.helpers.OSUtils;
41+
import processing.app.helpers.PreferencesMap;
4142

4243
public class CommandLineTest {
4344

@@ -82,4 +83,48 @@ public void testCommandLineBuildWithRelativePath() throws Exception {
8283
assertEquals(0, pr.exitValue());
8384
}
8485

86+
@Test
87+
public void testCommandLinePreferencesSave() throws Exception {
88+
Runtime rt = Runtime.getRuntime();
89+
File prefFile = File.createTempFile("test_pref", ".txt");
90+
prefFile.deleteOnExit();
91+
92+
Process pr = rt.exec(new String[] {
93+
arduinoPath.getAbsolutePath(),
94+
"--save-prefs",
95+
"--preferences-file", prefFile.getAbsolutePath(),
96+
"--get-pref", // avoids starting the GUI
97+
});
98+
IOUtils.copy(pr.getInputStream(), System.out);
99+
IOUtils.copy(pr.getErrorStream(), System.out);
100+
pr.waitFor();
101+
assertEquals(0, pr.exitValue());
102+
103+
pr = rt.exec(new String[] {
104+
arduinoPath.getAbsolutePath(),
105+
"--pref", "test_pref=xxx",
106+
"--preferences-file", prefFile.getAbsolutePath(),
107+
});
108+
IOUtils.copy(pr.getInputStream(), System.out);
109+
IOUtils.copy(pr.getErrorStream(), System.out);
110+
pr.waitFor();
111+
assertEquals(0, pr.exitValue());
112+
113+
PreferencesMap prefs = new PreferencesMap(prefFile);
114+
assertNull("preference should not be saved", prefs.get("test_pref"));
115+
116+
pr = rt.exec(new String[] {
117+
arduinoPath.getAbsolutePath(),
118+
"--pref", "test_pref=xxx",
119+
"--preferences-file", prefFile.getAbsolutePath(),
120+
"--save-prefs",
121+
});
122+
IOUtils.copy(pr.getInputStream(), System.out);
123+
IOUtils.copy(pr.getErrorStream(), System.out);
124+
pr.waitFor();
125+
assertEquals(0, pr.exitValue());
126+
127+
prefs = new PreferencesMap(prefFile);
128+
assertEquals("preference should be saved", "xxx", prefs.get("test_pref"));
129+
}
85130
}

0 commit comments

Comments
 (0)