JAL-629 --initsubstitutions as a bootstrap arg, new tests
[jalview.git] / test / jalview / bin / CommandsTest.java
index f7805fe..30c5e4e 100644 (file)
@@ -108,26 +108,53 @@ public class CommandsTest
             lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST"));
   }
 
-  @Test(groups = "Functional")
-  public void argFilesGlobAndSubstitutionsTest() throws IOException
+  @Test(groups = "Functional", dataProvider = "argfileOutputFiles")
+  public void argFilesGlobAndSubstitutionsTest(String cmdLine,
+          String[] filenames) throws IOException
   {
-    cleanupArgfilesImages();
-    String cmdLine = "--argfile=" + testfiles + "/dir*/argfile.txt";
+    cleanupFiles(filenames);
     String[] args = cmdLine.split("\\s+");
     Jalview.main(args);
     Commands cmds = Jalview.getInstance().getCommands();
-    File file1 = new File(png1);
-    File file2 = new File(png2);
-    Assert.assertTrue(file1.exists(),
-            "Did not make file " + png1 + " from argfile");
-    Assert.assertTrue(file2.exists(),
-            "Did not make file " + png2 + " from argfile");
-    long size1 = Files.size(file1.toPath());
-    long size2 = Files.size(file2.toPath());
-    Assert.assertTrue(file1.isFile() && size1 > 0);
-    Assert.assertTrue(file2.isFile() && size2 > 0);
-    Assert.assertTrue(size2 > size1); // png2 has three sequences, png1 has 2
-    cleanupArgfilesImages();
+    Assert.assertNotNull(cmds);
+    File lastFile = null;
+    for (String filename : filenames)
+    {
+      File file = new File(filename);
+      Assert.assertTrue(file.exists(), "File '" + filename
+              + "' was not created by '" + cmdLine + "'");
+      Assert.assertTrue(file.isFile(), "File '" + filename
+              + "' is not a file from '" + cmdLine + "'");
+      Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
+              + "' has no content from '" + cmdLine + "'");
+      // make sure the successive output files get bigger!
+      if (lastFile != null)
+        Assert.assertTrue(
+                Files.size(file.toPath()) > Files.size(lastFile.toPath()));
+    }
+    cleanupFiles(filenames);
+    tearDown();
+  }
+
+  @DataProvider(name = "argfileOutputFiles")
+  public Object[][] argfileOutputFiles()
+  {
+    return new Object[][] {
+        { "--argfile=" + testfiles + "/**/*.txt", new String[]
+        { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png",
+            testfiles + "/dir3/subdir/test0.png" } },
+        { "--argfile=" + testfiles + "/**/argfile.txt", new String[]
+        { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } },
+        { "--argfile=" + testfiles + "/dir*/argfile.txt", new String[]
+        { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } },
+        { "--initsubstitutions --open examples/uniref50.fa --image "
+                + testfiles + "/{basename}.png",
+            new String[]
+            { testfiles + "/uniref50.png" } },
+        { "--open examples/uniref50.fa --image " + testfiles
+                + "/{basename}.png",
+            new String[]
+            { testfiles + "/{basename}.png" } } };
   }
 
   @DataProvider(name = "cmdLines")
@@ -175,17 +202,15 @@ public class CommandsTest
     return false;
   }
 
-  public static void cleanupArgfilesImages()
+  public static void cleanupFiles(String[] filenames)
   {
-    File png1File = new File(png1);
-    File png2File = new File(png2);
-    if (png1File.exists())
-    {
-      png1File.delete();
-    }
-    if (png2File.exists())
+    for (String filename : filenames)
     {
-      png2File.delete();
+      File file = new File(filename);
+      if (file.exists())
+      {
+        file.delete();
+      }
     }
   }