X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fbin%2FCommandLineOperationsNG.java;h=56d430079f9c4a731a3720b068368aef555185bd;hb=82eb22b5c4cc991fad95822c71ab3ed90da759a6;hp=049e9a8936a9dca1d3005b8d33d978ab4b81b49a;hpb=e400c2aa8fe74794d496b72689ec73fd337edfa8;p=jalview.git diff --git a/test/jalview/bin/CommandLineOperationsNG.java b/test/jalview/bin/CommandLineOperationsNG.java index 049e9a8..56d4300 100644 --- a/test/jalview/bin/CommandLineOperationsNG.java +++ b/test/jalview/bin/CommandLineOperationsNG.java @@ -27,6 +27,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -161,6 +162,12 @@ public class CommandLineOperationsNG private Worker getJalviewDesktopRunner(boolean withAwt, String cmd, int timeout) { + return getJalviewDesktopRunner(withAwt, cmd, timeout, true); + } + + private Worker getJalviewDesktopRunner(boolean withAwt, String cmd, + int timeout, boolean testoutput) + { /* boolean win = System.getProperty("os.name").indexOf("Win") >= 0; String pwd = ""; @@ -193,7 +200,7 @@ public class CommandLineOperationsNG Worker worker = null; try { - cmd = " --testoutput " + cmd; + cmd = cmd + (testoutput ? " --testoutput " : ""); System.out.println("Running '" + _cmd + cmd + "'"); ls2_proc = Runtime.getRuntime().exec(_cmd + cmd); } catch (Throwable e1) @@ -333,9 +340,8 @@ public class CommandLineOperationsNG public void testAllInputOperations(String expectedString, String failureMsg) { - if ("[TESTOUTPUT] arg --nousagestats was set".equals(expectedString)) - Assert.assertTrue(successfulCMDs.contains(expectedString), - failureMsg); + Assert.assertTrue(successfulCMDs.contains(expectedString), + failureMsg + "; was expecting '" + expectedString + "'"); } @Test( @@ -352,7 +358,8 @@ public class CommandLineOperationsNG file.deleteOnExit(); Worker worker = getJalviewDesktopRunner(withAWT, cmd, timeout); assertNotNull(worker, "worker is null"); - String msg = "Didn't create an output" + type + " file.[" + cmd + "]"; + String msg = "Didn't create an output" + type + " file '" + fileName + + "'. [" + cmd + "]"; assertTrue(file.exists(), msg); FileAssert.assertFile(file, msg); FileAssert.assertMinLength(file, expectedMinFileSize); @@ -368,6 +375,42 @@ public class CommandLineOperationsNG file.delete(); } + @Test( + groups = + { "Functional", "testTask1" }, + dataProvider = "headlessModeOutputToStdout") + public void testHeadlessModeOutputToStdout(String args, + String comparisonFile, int timeout) + { + String cmd = args; + File file = new File(comparisonFile); + Worker worker = getJalviewDesktopRunner(true, cmd, timeout, false); + int b = -1; + StringBuilder sb = new StringBuilder(); + try + { + while ((b = worker.getOutputReader().read()) != -1) + { + sb.append(Character.toChars(b)); + } + } catch (IOException e) + { + Assert.fail("IOException whilst trying to read from jalview process"); + } + + String comparisonContent = null; + try + { + comparisonContent = new String(Files.readAllBytes(file.toPath())); + } catch (IOException e) + { + Assert.fail("IOException whilst trying to read comparison file"); + } + + Assert.assertEquals(sb.toString(), comparisonContent, + "STDOUT from jalview command did not match the comparison file"); + } + @DataProvider(name = "allInputOperationsData") public Object[][] getHeadlessModeInputParams() { @@ -459,4 +502,36 @@ public class CommandLineOperationsNG // }; } + + @DataProvider(name = "headlessModeOutputToStdout") + public static Object[][] getHeadlessModeOutputToStdout() + { + // JBPNote: I'm not clear why need to specify full path for output file + // when running tests on build server, but we will keep this patch for now + // since it works. + // https://issues.jalview.org/browse/JAL-1889?focusedCommentId=21609&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-21609 + String workingDir = "test/jalview/bin"; + return new Object[][] { + // + { "--open=examples/uniref50.fa --output=-", + workingDir + "/uniref50-output.fa", TEST_TIMEOUT }, + { "--open examples/uniref50.fa --output -", + workingDir + "/uniref50-output.fa", TEST_TIMEOUT }, + { "--open examples/uniref50.fa --output=[format=blc]-", + workingDir + "/uniref50-output.blc", TEST_TIMEOUT }, + { "--open examples/uniref50.fa --output - --format blc", + workingDir + "/uniref50-output.blc", TEST_TIMEOUT }, + { "./examples/uniref50.fa --output=-", + workingDir + "/uniref50-output.fa", TEST_TIMEOUT }, + { "./examples/uniref50.fa --output - --format blc", + workingDir + "/uniref50-output.blc", TEST_TIMEOUT }, + // remember you can't use shell wildcards for filenames in a test + { "./test/jalview/bin/argparser/testfiles/test1.fa ./test/jalview/bin/argparser/testfiles/test2.fa ./test/jalview/bin/argparser/testfiles/test3.fa --all --output -", + workingDir + "/test1-3.fa", TEST_TIMEOUT }, + // but you can use java wildcards when using an equals sign + { "--open=./test/jalview/bin/argparser/testfiles/test*.fa --all --output -", + workingDir + "/test1-3.fa", TEST_TIMEOUT }, + // + }; + } }