Skip to content

Commit

Permalink
Added some simple tests of the command line API
Browse files Browse the repository at this point in the history
It's not *properly* testing anything, but it does check that things are
not totally silly.

Note that this code is currently unavoidably impacted by:
* stefanbirkner/system-lambda#27
* https://bugs.openjdk.org/browse/JDK-8199704
  • Loading branch information
dkfellows committed Jan 6, 2023
1 parent 6cc8b65 commit 867267c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
4 changes: 4 additions & 0 deletions SpiNNaker-front-end/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-lambda</artifactId>
</dependency>
</dependencies>
<description>The front-end interface. NB: not a GUI!</description>
<name>SpiNNaker Front End Interface</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ public static void main(String... args) {
var cmd = new CommandLine(new CommandLineInterface());
if (args.length == 0) {
cmd.usage(cmd.getErr());
System.exit(USAGE);
} else {
cmd.execute(args);
System.exit(cmd.execute(args));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,70 @@
*/
package uk.ac.manchester.spinnaker.front_end;

import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized;
import static java.lang.String.format;
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Disabled;
import java.util.List;

import org.junit.jupiter.api.Test;

class TestFrontEnd {

/**
* Run the command line, trapping its exit and comparing it with an expected
* value.
* <p>
* This produces <em>one non-suppressable warning</em> due to
* deprecation-for-removal in Java 17.
*
* @param expectedCode
* The expected exit code.
* @param args
* The arguments to pass to the command line.
* @throws Exception
* If anything goes wrong.
* @see <a href="https://github.com/stefanbirkner/system-lambda/issues/27">
* System Lambda Issue #27</a>
* @see <a href="https://bugs.openjdk.org/browse/JDK-8199704">JDK Issue
* #8199704</a>
*/
private static void runExpecting(int expectedCode, String... args)
throws Exception {
int code = catchSystemExit(() -> CommandLineInterface.main(args));
assertEquals(expectedCode, code);
}

@Test
void testHelp() throws Exception {
var msg = tapSystemOutNormalized(() -> {
runExpecting(0, "help");
});
var requiredSubcommands = List.of("dse_app_mon", "gather");
var requiredArgs = List.of("<machineFile>", "<runFolder>");
for (var cmd: requiredSubcommands) {
assertTrue(msg.contains(cmd),
() -> format("help message does not contain '%s': %s", cmd,
msg));
var msg2 = tapSystemOutNormalized(() -> {
runExpecting(0, "help", cmd);
});
for (var arg : requiredArgs) {
assertTrue(msg2.contains(arg),
() -> format("help message does not contain '%s': %s",
arg, msg2));
}
}
}

@Test
@Disabled("Not yet implemented")
void test() {
fail("Not yet implemented");
void testVersion() throws Exception {
var msg = tapSystemOutNormalized(() -> {
runExpecting(0, "--version");
});
assertTrue(msg.contains(" version "),
() -> format("message '%s' does not contain 'version'", msg));
}

}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<artifactId>javax.el</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-lambda</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 867267c

Please sign in to comment.