4 import java.io.IOException;
6 import java.util.Properties;
8 import org.testng.Assert;
9 import org.testng.annotations.AfterClass;
10 import org.testng.annotations.DataProvider;
11 import org.testng.annotations.Test;
13 import jalview.bin.argparser.Arg;
14 import jalview.bin.argparser.ArgParser;
15 import jalview.bin.argparser.BootstrapArgs;
17 @Test(singleThreaded = true)
18 public class ArgParserTest
20 @AfterClass(alwaysRun = true)
21 public static void resetProps()
23 Cache.applicationProperties.clear();
24 Cache.loadProperties("test/jalview/testProps.jvprops");
27 @Test(groups = "Functional", dataProvider = "argLines")
28 public void parseArgsAndSubValsTest(String commandLineArgs, Arg a,
31 String[] args = commandLineArgs.split("\\s*");
32 ArgParser argparser = new ArgParser(args);
35 @Test(groups = "Functional", dataProvider = "argLines")
36 public void bootstrapArgsTest(String commandLineArgs, Arg a, String other)
38 String[] args = commandLineArgs.split("\\s+");
39 BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
41 Assert.assertTrue(b.contains(a));
44 Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
45 Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST)));
46 Assert.assertFalse(bP.contains("NOT" + Cache.BOOTSTRAP_TEST));
48 else if (a == Arg.ARGFILE)
50 List<String> filenames = b.getList(a);
51 boolean found = false;
52 for (String s : filenames)
55 File fo = new File(other);
58 if (fo.getCanonicalPath().equals(f.getCanonicalPath()))
63 } catch (IOException e)
67 Assert.assertTrue(found,
68 "File '" + other + "' not found in shell expanded glob '"
69 + commandLineArgs + "'");
74 @Test(groups = "Functional", dataProvider = "argFiles")
75 public void argFilesTest(String commandLineArgs, Arg a, String other)
77 String[] args = commandLineArgs.split("\\s+");
78 BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
80 Assert.assertTrue(b.contains(a));
81 Assert.assertFalse(b.contains(Arg.OPEN));
84 Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
85 Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST)));
89 @DataProvider(name = "argLinesNotworking")
90 public Object[][] argLinesTest()
92 return new Object[][] {
93 // can't use this one yet as it doesn't get shell glob expanded by the
95 { "--argfile test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
96 "test/jalview/bin/argparser/argfile0.txt" }, };
99 @DataProvider(name = "argLines")
100 public Object[][] argLines()
102 return new Object[][] {
103 { "--debug --open=test/jalview/bin/argparser/test1.fa", Arg.DEBUG,
105 { "--open=test/jalview/bin/argparser/test1.fa --headless",
106 Arg.HEADLESS, null },
107 { "--open=test/jalview/bin/argparser/test1.fa --props=test/jalview/bin/argparser/testProps.jvprops",
109 { "--argfile test/jalview/bin/argparser/argfile0.txt", Arg.ARGFILE,
110 "test/jalview/bin/argparser/argfile0.txt" },
111 // these next three are what a shell glob expansion would look like
112 { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt",
113 Arg.ARGFILE, "test/jalview/bin/argparser/argfile0.txt" },
114 { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt",
115 Arg.ARGFILE, "test/jalview/bin/argparser/argfile1.txt" },
116 { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt",
117 Arg.ARGFILE, "test/jalview/bin/argparser/argfile2.txt" },
118 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
119 "test/jalview/bin/argparser/argfile0.txt" },
120 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
121 "test/jalview/bin/argparser/argfile1.txt" },
122 { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE,
123 "test/jalview/bin/argparser/argfile2.txt" } };
127 @DataProvider(name = "argFiles")
128 public Object[][] argFiles()
130 return new Object[][] { {
131 "--argfile=test/jalview/bin/argparser/argfile0.txt --open=shouldntbeabootstrap",
132 Arg.ARGFILE, "test/jalview/bin/argfiles/test1.fa" } };