4 import java.io.IOException;
6 import java.util.Properties;
8 import org.testng.Assert;
9 import org.testng.annotations.DataProvider;
10 import org.testng.annotations.Test;
12 import jalview.bin.ArgParser.Arg;
13 import jalview.bin.ArgParser.BootstrapArgs;
15 @Test(singleThreaded = true)
16 public class ArgParserTest
19 @Test(groups = "Functional", dataProvider = "argLines")
20 public void parseArgsAndSubValsTest(String commandLineArgs, Arg a,
23 String[] args = commandLineArgs.split("\\s*");
24 ArgParser argparser = new ArgParser(args);
27 @Test(groups = "Functional", dataProvider = "argLines")
28 public void bootstrapArgsTest(String commandLineArgs, Arg a, String other)
30 String[] args = commandLineArgs.split("\\s+");
31 BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
33 Assert.assertTrue(b.contains(a));
36 Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
37 Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST)));
38 Assert.assertFalse(bP.contains("NOT" + Cache.BOOTSTRAP_TEST));
40 else if (a == Arg.ARGFILE)
42 List<String> filenames = b.getList(a);
43 boolean found = false;
44 for (String s : filenames)
47 File fo = new File(other);
50 if (fo.getCanonicalPath().equals(f.getCanonicalPath()))
55 } catch (IOException e)
59 Assert.assertTrue(found,
60 "File '" + other + "' not found in shell expanded glob '"
61 + commandLineArgs + "'");
66 @Test(groups = "Functional", dataProvider = "argFiles")
67 public void argFilesTest(String commandLineArgs, Arg a, String other)
69 String[] args = commandLineArgs.split("\\s+");
70 BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
72 Assert.assertTrue(b.contains(a));
73 Assert.assertFalse(b.contains(Arg.OPEN));
76 Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
77 Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST)));
81 @DataProvider(name = "argLinesNotworking")
82 public Object[][] argLinesTest()
84 return new Object[][] {
85 // can't use this one yet as it doesn't get shell glob expanded by the
87 { "--argfile test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
88 "test/jalview/bin/argparser/argfile0.txt" }, };
91 @DataProvider(name = "argLines")
92 public Object[][] argLines()
94 return new Object[][] {
95 { "--debug --open=test/jalview/bin/argparser/test1.fa", Arg.DEBUG,
97 { "--open=test/jalview/bin/argparser/test1.fa --headless",
99 { "--open=test/jalview/bin/argparser/test1.fa --props=test/jalview/bin/argparser/testProps.jvprops",
101 { "--argfile test/jalview/bin/argparser/argfile0.txt", Arg.ARGFILE,
102 "test/jalview/bin/argparser/argfile0.txt" },
103 // these next three are what a shell glob expansion would look like
104 { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt",
105 Arg.ARGFILE, "test/jalview/bin/argparser/argfile0.txt" },
106 { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt",
107 Arg.ARGFILE, "test/jalview/bin/argparser/argfile1.txt" },
108 { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt",
109 Arg.ARGFILE, "test/jalview/bin/argparser/argfile2.txt" },
110 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
111 "test/jalview/bin/argparser/argfile0.txt" },
112 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
113 "test/jalview/bin/argparser/argfile1.txt" },
114 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
115 "test/jalview/bin/argparser/argfile2.txt" } };
119 @DataProvider(name = "argFiles")
120 public Object[][] argFiles()
122 return new Object[][] { {
123 "--argfile=test/jalview/bin/argparser/argfile0.txt --open=shouldntbeabootstrap",
124 Arg.ARGFILE, "test/jalview/bin/argfiles/test1.fa" } };