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 public class ArgParserTest
18 @Test(groups = "Functional", dataProvider = "argLines")
19 public void parseArgsAndSubValsTest(String commandLineArgs, Arg a,
22 String[] args = commandLineArgs.split("\\s*");
23 ArgParser argparser = new ArgParser(args);
26 @Test(groups = "Functional", dataProvider = "argLines")
27 public void bootstrapArgsTest(String commandLineArgs, Arg a, String other)
29 String[] args = commandLineArgs.split("\\s+");
30 BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
32 Assert.assertTrue(b.contains(a));
35 Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
36 Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST)));
37 Assert.assertFalse(bP.contains("NOT" + Cache.BOOTSTRAP_TEST));
39 else if (a == Arg.ARGFILE)
41 List<String> filenames = b.getList(a);
42 boolean found = false;
43 for (String s : filenames)
46 File fo = new File(other);
49 if (fo.getCanonicalPath().equals(f.getCanonicalPath()))
54 } catch (IOException e)
58 Assert.assertTrue(found,
59 "File '" + other + "' not found in shell expanded glob '"
60 + commandLineArgs + "'");
65 @Test(groups = "Functional", dataProvider = "argFiles")
66 public void argFilesTest(String commandLineArgs, Arg a, String other)
68 String[] args = commandLineArgs.split("\\s+");
69 BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
71 Assert.assertTrue(b.contains(a));
72 Assert.assertFalse(b.contains(Arg.OPEN));
75 Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
76 Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST)));
80 @DataProvider(name = "argLinesTest")
81 public Object[][] argLinesTest()
83 return new Object[][] {
84 // can't use this one yet as it doesn't get shell expanded
85 { "--argfile test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
86 "test/jalview/bin/argparser/argfile0.txt" }, };
89 @DataProvider(name = "argLines")
90 public Object[][] argLines()
92 return new Object[][] {
93 { "--debug --open=test/jalview/bin/argparser/test1.fa", Arg.DEBUG,
95 { "--open=test/jalview/bin/argparser/test1.fa --headless",
97 { "--open=test/jalview/bin/argparser/test1.fa --props=test/jalview/bin/argparser/testProps.jvprops",
99 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
100 "test/jalview/bin/argparser/argfile0.txt" },
101 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
102 "test/jalview/bin/argparser/argfile1.txt" },
103 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
104 "test/jalview/bin/argparser/argfile2.txt" } };
107 @DataProvider(name = "argFiles")
108 public Object[][] argFiles()
110 return new Object[][] { {
111 "--argfile=test/jalview/bin/argparser/argfile0.txt --open=shouldntbeabootstrap",
112 Arg.ARGFILE, "test/jalview/bin/argfiles/test1.fa" } };