Skip to content

Commit

Permalink
[MJLINK-88] separate Windows and Unix command line tests (#227)
Browse files Browse the repository at this point in the history
* split Unix and windows tests
  • Loading branch information
elharo authored Dec 3, 2024
1 parent 3a466c1 commit 7caf7bf
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,38 @@
import java.util.List;

import org.apache.maven.shared.utils.cli.Commandline;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

import static org.assertj.core.api.Assertions.assertThat;

public class JLinkMojoTest {

@Test
void double_quote_every_argument() throws Exception {
private JLinkMojo mojo = new JLinkMojo();

@BeforeEach
public void setUp() throws NoSuchFieldException, IllegalAccessException {
// given
JLinkMojo mojo = new JLinkMojo();
Field stripDebug = mojo.getClass().getDeclaredField("stripDebug");
stripDebug.setAccessible(true);
stripDebug.set(mojo, Boolean.TRUE);
}

@Test
void double_quote_every_argument() throws Exception {
// when
List<String> jlinkArgs = mojo.createJlinkArgs(List.of(), List.of());

// then
assertThat(jlinkArgs).noneMatch(arg -> arg.trim().isBlank());
}

@DisabledOnOs(OS.WINDOWS)
@Test
void single_quotes_shell_command() throws Exception {
// given
JLinkMojo mojo = new JLinkMojo();
Field stripDebug = mojo.getClass().getDeclaredField("stripDebug");
stripDebug.setAccessible(true);
stripDebug.set(mojo, Boolean.TRUE);

void single_quotes_shell_command_unix() throws Exception {
// when
List<String> jlinkArgs = mojo.createJlinkArgs(List.of("foo", "bar"), List.of("mvn", "jlink"));
Commandline cmdLine = JLinkExecutor.createJLinkCommandLine(new File("/path/to/jlink"), jlinkArgs);
Expand All @@ -61,4 +64,18 @@ void single_quotes_shell_command() throws Exception {
.isEqualTo(
"/bin/sh -c '/path/to/jlink \"--strip-debug\" \"--module-path\" \"foo:bar\" \"--add-modules\" \"mvn,jlink\"'");
}

@EnabledOnOs(OS.WINDOWS)
@Test
void single_quotes_shell_command_windows() throws Exception {
// when
List<String> jlinkArgs = mojo.createJlinkArgs(List.of("foo", "bar"), List.of("mvn", "jlink"));
Commandline cmdLine = JLinkExecutor.createJLinkCommandLine(new File("/path/to/jlink"), jlinkArgs);

// then
assertThat(cmdLine.toString()).startsWith("cmd.exe ");
assertThat(cmdLine.toString())
.contains(
"\\path\\to\\jlink \"--strip-debug\" \"--module-path\" \"foo;bar\" \"--add-modules\" \"mvn,jlink");
}
}

0 comments on commit 7caf7bf

Please sign in to comment.