Skip to content

Commit

Permalink
Added more command files tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Aug 5, 2024
1 parent d72e6eb commit 0382444
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public CommandLineTokenizer(Reader input) throws IOException {
}

public String nextToken() throws IOException {
skipWhitespaceOrComments();
trimWhitespaceOrComments();
if (ch_ == -1) {
return null;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ private char handleEscapeSequence() {
}


private void skipWhitespaceOrComments() throws IOException {
private void trimWhitespaceOrComments() throws IOException {
while (ch_ != -1) {
if (Character.isWhitespace(ch_)) { // Skip whitespaces
ch_ = input_.read();
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/rife/bld/operations/JpackageOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @since 2.0.2
*/
public class JpackageOperation extends AbstractToolProviderOperation<JpackageOperation> {
private final List<String> fileOptions_ = new ArrayList<>();
private final List<String> cmdFiles_ = new ArrayList<>();
private final JpackageOptions jpackageOptions_ = new JpackageOptions();

public JpackageOperation() {
Expand All @@ -24,7 +24,7 @@ public JpackageOperation() {

@Override
public void execute() throws Exception {
toolArgs(fileOptions_.stream().map(opt -> '@' + opt).toList());
toolArgs(cmdFiles_.stream().map(opt -> '@' + opt).toList());
toolArgs(jpackageOptions_);
super.execute();
}
Expand All @@ -35,17 +35,17 @@ public void execute() throws Exception {
* @return the list of files
*/
public List<String> fileOptions() {
return fileOptions_;
return cmdFiles_;
}

/**
* Read options and/or mode from a file.
* Read options and/or mode from file(s).
*
* @param file one or more file
* @return this operation instance
*/
public JpackageOperation fileOptions(String... file) {
fileOptions_.addAll(List.of(file));
public JpackageOperation cmdFiles(String... file) {
cmdFiles_.addAll(List.of(file));
return this;
}

Expand Down
38 changes: 19 additions & 19 deletions src/test/java/rife/bld/operations/TestJlinkOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ void testArguments() {
assertEquals("name-2=module-2", options.get("--launcher"), "incorrect launcher");
}

@Test
void testCmdFiles() {
System.setOut(new PrintStream(outputStreamCaptor));
var jlink = new JlinkOperation().cmdFiles("src/test/resources/jlink/options_jlink.txt");
assertDoesNotThrow(jlink::execute);
var out = outputStreamCaptor.toString();
assertTrue(out.contains("List of available plugins:"), out);
}

@Test
void testCmdFilesMulti() {
System.setOut(new PrintStream(outputStreamCaptor));
var jlink = new JlinkOperation().cmdFiles("src/test/resources/jlink/options_verbose.txt",
"src/test/resources/jlink/options_version.txt");
assertDoesNotThrow(jlink::execute);
var out = outputStreamCaptor.toString();
assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out);
}

@Test
void testDisablePlugin() {
System.setOut(new PrintStream(outputStreamCaptor));
Expand Down Expand Up @@ -113,16 +132,6 @@ void testExecute() throws IOException {
}
}

@Test
void testFileOptions() {
System.setOut(new PrintStream(outputStreamCaptor));
var jlink = new JlinkOperation().cmdFiles("src/test/resources/jlink/options_verbose.txt",
"src/test/resources/jlink/options_version.txt");
assertDoesNotThrow(jlink::execute);
var out = outputStreamCaptor.toString();
assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out);
}

@Test
void testHelp() {
var jlink = new JlinkOperation().toolArgs("--help");
Expand All @@ -138,15 +147,6 @@ void testNoArguments() {
assertThrows(ExitStatusException.class, jlink::execute);
}

@Test
void testParseOptions() {
System.setOut(new PrintStream(outputStreamCaptor));
var jlink = new JlinkOperation().cmdFiles("src/test/resources/jlink/options_jlink.txt");
assertDoesNotThrow(jlink::execute);
var out = outputStreamCaptor.toString();
assertTrue(out.contains("List of available plugins:"), out);
}

@Test
void testVersion() {
System.setOut(new PrintStream(outputStreamCaptor));
Expand Down
36 changes: 27 additions & 9 deletions src/test/java/rife/bld/operations/TestJmodOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,40 @@ void testArguments() {
}
}

@Test
void testCmdFiles() {
System.setOut(new PrintStream(outputStreamCaptor));
var jmod = new JmodOperation().cmdFiles("src/test/resources/jlink/options_version.txt");
assertDoesNotThrow(jmod::execute);
var out = outputStreamCaptor.toString();
assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out);
}

@Test
void testCmdFilesCreate() throws IOException {
var tmpdir = Files.createTempDirectory("bld-jmod-test").toFile();
try {
var mod = new File(tmpdir, "dev.mccue.tree.jmod");

var jmod = new JmodOperation()
.cmdFiles("src/test/resources/jlink/options_jmod.txt")
.jmodFile(mod.getAbsolutePath());

assertDoesNotThrow(jmod::execute);
assertTrue(mod.exists(), "mod does not exist");
} finally {
FileUtils.deleteDirectory(tmpdir);
}
}

@Test
void testCreate() throws IOException {
var tmpdir = Files.createTempDirectory("bld-jmod-test").toFile();
try {
var mod = new File(tmpdir, "dev.mccue.tree.jmod");

var options = new JmodOptions()
.date(ZonedDateTime.now())
.legalNotices("src/test/resources/jlink/dev.mccue.apple/legal")
.classpath("src/test/resources/jlink/build/jar/dev.mccue.apple.jar");
var jmod = new JmodOperation()
Expand Down Expand Up @@ -138,15 +165,6 @@ void testExecute() throws IOException {
}
}

@Test
void testFileOptions() {
System.setOut(new PrintStream(outputStreamCaptor));
var jmod = new JmodOperation().cmdFiles("src/test/resources/jlink/options_version.txt");
assertDoesNotThrow(jmod::execute);
var out = outputStreamCaptor.toString();
assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out);
}

@Test
void testHelp() {
var jmod = new JmodOperation().toolArgs("--help-extra");
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/rife/bld/operations/TestJpackageOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ void testCreatePackage() throws Exception {
}

@Test
void testFileOptions() {
void testCmdFiles() {
System.setOut(new PrintStream(outputStreamCaptor));
var jpackage = new JpackageOperation().fileOptions("src/test/resources/jlink/options_verbose.txt",
var jpackage = new JpackageOperation().cmdFiles("src/test/resources/jlink/options_verbose.txt",
"src/test/resources/jlink/options_version.txt");
assertDoesNotThrow(jpackage::execute);
var out = outputStreamCaptor.toString();
Expand Down
7 changes: 4 additions & 3 deletions src/test/resources/jlink/options_jlink.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
--verbose --version #foo
--module-path "foo bar" --list-plugins
# bar
--verbose --version #--foo
--module-path "\'foo\' \"bar\" --bar" --list-plugins
--output foo --bind-services

# bar
3 changes: 3 additions & 0 deletions src/test/resources/jlink/options_jmod.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
create
--legal-notices src/test/resources/jlink/dev.mccue.apple/legal
--class-path src/test/resources/jlink/build/jar/dev.mccue.apple.jar

0 comments on commit 0382444

Please sign in to comment.