|
29 | 29 |
|
30 | 30 | package processing.app;
|
31 | 31 |
|
32 |
| -import static org.junit.Assert.assertEquals; |
| 32 | +import static org.junit.Assert.*; |
33 | 33 |
|
34 | 34 | import java.io.File;
|
35 | 35 |
|
|
38 | 38 | import org.junit.Test;
|
39 | 39 |
|
40 | 40 | import processing.app.helpers.OSUtils;
|
| 41 | +import processing.app.helpers.PreferencesMap; |
41 | 42 |
|
42 | 43 | public class CommandLineTest {
|
43 | 44 |
|
@@ -82,4 +83,48 @@ public void testCommandLineBuildWithRelativePath() throws Exception {
|
82 | 83 | assertEquals(0, pr.exitValue());
|
83 | 84 | }
|
84 | 85 |
|
| 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 | +} |
85 | 130 | }
|
0 commit comments