|
18 | 18 | import static com.google.common.truth.Truth8.assertThat;
|
19 | 19 | import static java.nio.charset.StandardCharsets.UTF_8;
|
20 | 20 | import static org.junit.Assert.fail;
|
| 21 | +import static org.junit.Assert.assertThrows; |
21 | 22 |
|
22 | 23 | import com.google.common.collect.ImmutableList;
|
23 | 24 | import com.google.common.collect.Range;
|
@@ -179,6 +180,44 @@ public void paramsFile() throws IOException {
|
179 | 180 | assertThat(options.files()).containsExactly("L", "M", "ℕ", "@O", "P", "Q");
|
180 | 181 | }
|
181 | 182 |
|
| 183 | + @Test |
| 184 | + public void paramsFileWithNesting() throws IOException { |
| 185 | + Path outer = testFolder.newFile("outer").toPath(); |
| 186 | + Path exit = testFolder.newFile("exit").toPath(); |
| 187 | + Path nested1 = testFolder.newFile("nested1").toPath(); |
| 188 | + Path nested2 = testFolder.newFile("nested2").toPath(); |
| 189 | + Path nested3 = testFolder.newFile("nested3").toPath(); |
| 190 | + |
| 191 | + String[] args = {"--dry-run", "@" + exit, "L", "@" + outer, "U"}; |
| 192 | + |
| 193 | + Files.write(exit, "--set-exit-if-changed".getBytes(UTF_8)); |
| 194 | + Files.write(outer, ("M\n@" + nested1.toAbsolutePath() + "\nT").getBytes(UTF_8)); |
| 195 | + Files.write(nested1, ("ℕ\n@" + nested2.toAbsolutePath() + "\nS").getBytes(UTF_8)); |
| 196 | + Files.write(nested2, ("O\n@" + nested3.toAbsolutePath() + "\nR").getBytes(UTF_8)); |
| 197 | + Files.write(nested3, "P\n\n \n@@Q\n".getBytes(UTF_8)); |
| 198 | + |
| 199 | + CommandLineOptions options = CommandLineOptionsParser.parse(Arrays.asList(args)); |
| 200 | + assertThat(options.files()).containsExactly("L", "M", "ℕ", "O", "P", "@Q", "R", "S", "T", "U"); |
| 201 | + } |
| 202 | + |
| 203 | + @Test |
| 204 | + public void paramsFileWithRecursion() throws IOException { |
| 205 | + Path outer = testFolder.newFile("outer").toPath(); |
| 206 | + Path exit = testFolder.newFile("exit").toPath(); |
| 207 | + Path nested1 = testFolder.newFile("nested1").toPath(); |
| 208 | + Path nested2 = testFolder.newFile("nested2").toPath(); |
| 209 | + |
| 210 | + String[] args = {"--dry-run", "@" + exit, "L", "@" + outer, "U"}; |
| 211 | + |
| 212 | + Files.write(exit, "--set-exit-if-changed".getBytes(UTF_8)); |
| 213 | + Files.write(outer, ("M\n@" + nested1.toAbsolutePath() + "\nT").getBytes(UTF_8)); |
| 214 | + Files.write(nested1, ("ℕ\n@" + nested2.toAbsolutePath() + "\nS").getBytes(UTF_8)); |
| 215 | + Files.write(nested2, ("O\n@" + nested1.toAbsolutePath() + "\nR").getBytes(UTF_8)); |
| 216 | + |
| 217 | + Exception exception = assertThrows(IllegalArgumentException.class, () -> CommandLineOptionsParser.parse(Arrays.asList(args))); |
| 218 | + assertThat(exception.getMessage().startsWith("parameter file was included recursively: ")).isTrue(); |
| 219 | + } |
| 220 | + |
182 | 221 | @Test
|
183 | 222 | public void assumeFilename() {
|
184 | 223 | assertThat(
|
|
0 commit comments