-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fb719f
commit f87621b
Showing
8 changed files
with
230 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
package dk.xam.jbang; | ||
|
||
public class ExitException extends Throwable { | ||
public ExitException(int status) { | ||
} | ||
/** | ||
* Used when wanting to exit app from a command. | ||
*/ | ||
public class ExitException extends RuntimeException { | ||
|
||
private final int status; | ||
|
||
public ExitException(int status) { | ||
this.status = status; | ||
} | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,78 @@ | ||
package dk.xam.jbang; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import picocli.CommandLine; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class TestArguments { | ||
|
||
private CommandLine cli; | ||
private Main main; | ||
|
||
@BeforeEach | ||
void setup() { | ||
cli = Main.getCommandLine(); | ||
main = cli.getCommand(); | ||
} | ||
|
||
@Test | ||
public void testBasicArguments() { | ||
var arg = new Main(); | ||
new CommandLine(arg).parseArgs("-h", "--debug", "myfile.java"); | ||
cli.parseArgs("-h", "--debug", "myfile.java"); | ||
|
||
assert arg.helpRequested; | ||
assert arg.debug; | ||
assertEquals(1, arg.params.size()); | ||
assert main.helpRequested; | ||
assertThat(main.debug, is(true)); | ||
assertThat(main.scriptOrFile, is("myfile.java")); | ||
assertThat(main.params.size(), is(0)); | ||
|
||
} | ||
|
||
@Test | ||
public void testArgumentsForJbang() { | ||
|
||
var a = Main.argsForJbang("test.java"); | ||
assertThat(a, is(new String[] {"test.java"})); | ||
|
||
a = Main.argsForJbang("--debug", "test.java"); | ||
assertThat(a, is(new String[]{"--debug", "--", "test.java"})); | ||
public void testDoubleDebug() { | ||
cli.parseArgs("--debug", "test.java", "--debug", "wonka"); | ||
assertThat(main.debug, is(true)); | ||
assertThat(main.scriptOrFile, is("test.java")); | ||
assertThat(main.params, is(Arrays.asList("--debug", "wonka"))); | ||
} | ||
|
||
a = Main.argsForJbang("test.java", "-h"); | ||
assertThat(a, is(new String[]{"test.java", "-h"})); | ||
/** | ||
* @Test public void testInit() { cli.parseArgs("--init", "x.java", "y.java"); | ||
* assertThat(main.script, is("x.java")); assertThat(main.params, | ||
* is(Arrays.asList("x.java", "y.java"))); } | ||
**/ | ||
|
||
a = Main.argsForJbang("-", "--help"); | ||
assertThat(a, is(new String[]{"-", "--help"})); | ||
@Test | ||
public void testStdInWithHelpParam() { | ||
cli.parseArgs("-", "--help"); | ||
assertThat(main.scriptOrFile, is("-")); | ||
assertThat(main.helpRequested, is(false)); | ||
assertThat(main.params, is(Arrays.asList("--help"))); | ||
} | ||
|
||
a = Main.argsForJbang("--init", "x.java", "y.java"); | ||
assertThat(a, is(new String[]{"--init", "--", "x.java", "y.java"})); | ||
@Test | ||
public void testScriptWithHelpParam() { | ||
cli.parseArgs("test.java", "-h"); | ||
assertThat(main.scriptOrFile, is("test.java")); | ||
assertThat(main.helpRequested, is(false)); | ||
assertThat(main.params, is(Arrays.asList("-h"))); | ||
} | ||
|
||
a = Main.argsForJbang("--debug", "test.java", "--debug", "wonka"); | ||
assertThat(a, is(new String[]{"--debug", "--", "test.java", "--debug", "wonka"})); | ||
@Test | ||
public void testDebugWithScript() { | ||
cli.parseArgs("--debug", "test.java"); | ||
assertThat(main.scriptOrFile, is("test.java")); | ||
assertThat(main.debug, is(true)); | ||
} | ||
|
||
@Test | ||
public void testSimpleScript() { | ||
cli.parseArgs("test.java"); | ||
assertThat(main.scriptOrFile, is("test.java")); | ||
} | ||
|
||
} |
Oops, something went wrong.