1 package jalview.bin.argparser;
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.Cache;
15 @Test(singleThreaded = true)
16 public class ArgParserTest
18 @AfterClass(alwaysRun = true)
19 public static void resetProps()
21 Cache.loadProperties("test/jalview/testProps.jvprops");
24 @Test(groups = "Functional", dataProvider = "argLines")
25 public void parseArgsTest(String commandLineArgs, Arg a, String other)
27 String[] args = commandLineArgs.split("\\s+");
28 ArgParser argparser = new ArgParser(args);
31 @Test(groups = "Functional", dataProvider = "argSubValsAndLinkedIds")
32 public void parseSubValsAndLinkedIdsTest(String commandLineArgs,
33 String linkedId, Arg a, String subvalKey, String value,
36 String[] args = commandLineArgs.split("\\s+");
37 ArgParser argparser = new ArgParser(args);
38 ArgValuesMap avm = argparser.linkedArgs(linkedId);
39 ArgValue av = avm.getArgValue(a);
40 SubVals sv = av.getSubVals();
41 String testString = null;
42 if (subvalKey.equals("GETINDEX"))
44 testString = String.valueOf(sv.getIndex());
48 testString = sv.get(subvalKey);
52 Assert.assertEquals(testString, value);
56 Assert.assertNotEquals(testString, value);
61 groups = "Functional",
62 dataProvider = "argAutoIndexAndSubstitutions")
63 public void parseAutoIndexAndSubstitutionsTest(String commandLineArgs,
64 String linkedId, Arg a, String filename)
66 // { "--open=filename0 --increment --open=filename1", "JALVIEW:1", Arg.OPEN,
68 String[] args = commandLineArgs.split("\\s+");
69 ArgParser argparser = new ArgParser(args);
70 ArgValuesMap avm = argparser.linkedArgs(linkedId);
71 ArgValue av = avm.getArgValue(a);
72 Assert.assertEquals(av.getValue(), filename);
75 @Test(groups = "Functional", dataProvider = "argLines")
76 public void bootstrapArgsTest(String commandLineArgs, Arg a, String other)
78 String[] args = commandLineArgs.split("\\s+");
79 BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
81 Assert.assertTrue(b.contains(a));
84 Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
85 Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST)));
86 Assert.assertFalse(bP.contains("NOT" + Cache.BOOTSTRAP_TEST));
88 else if (a == Arg.ARGFILE)
90 List<String> filenames = b.getList(a);
91 boolean found = false;
92 for (String s : filenames)
95 File fo = new File(other);
98 if (fo.getCanonicalPath().equals(f.getCanonicalPath()))
103 } catch (IOException e)
107 Assert.assertTrue(found,
108 "File '" + other + "' not found in shell expanded glob '"
109 + commandLineArgs + "'");
113 @Test(groups = "Functional", dataProvider = "argFiles")
114 public void argFilesTest(String commandLineArgs, Arg a, String other)
116 String[] args = commandLineArgs.split("\\s+");
117 BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args);
119 Assert.assertTrue(b.contains(a));
120 Assert.assertFalse(b.contains(Arg.OPEN));
123 Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
124 Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST)));
128 @DataProvider(name = "argLinesNotworking")
129 public Object[][] argLinesTest()
131 return new Object[][] {
132 // can't use this one yet as it doesn't get shell glob expanded by the
134 { "--argfile test/jalview/bin/argparser/testfiles/argfile*.txt",
136 "test/jalview/bin/argparser/testfiles/argfile0.txt" }, };
139 @DataProvider(name = "argLines")
140 public Object[][] argLines()
142 return new Object[][] {
143 { "--debug --open=test/jalview/bin/argparser/testfiles/test1.fa",
145 { "--open=test/jalview/bin/argparser/testfiles/test1.fa --headless",
146 Arg.HEADLESS, null },
147 { "--open=test/jalview/bin/argparser/testfiles/test1.fa --props=test/jalview/bin/argparser/testfiles/testProps.jvprops",
149 { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt",
151 "test/jalview/bin/argparser/testfiles/argfile0.txt" },
152 // these next three are what a shell glob expansion would look like
153 { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt test/jalview/bin/argparser/testfiles/argfile1.txt test/jalview/bin/argparser/testfiles/argfile2.txt",
155 "test/jalview/bin/argparser/testfiles/argfile0.txt" },
156 { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt test/jalview/bin/argparser/testfiles/argfile1.txt test/jalview/bin/argparser/testfiles/argfile2.txt",
158 "test/jalview/bin/argparser/testfiles/argfile1.txt" },
159 { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt test/jalview/bin/argparser/testfiles/argfile1.txt test/jalview/bin/argparser/testfiles/argfile2.txt",
161 "test/jalview/bin/argparser/testfiles/argfile2.txt" },
162 { "--argfile=test/jalview/bin/argparser/testfiles/argfile*.txt",
164 "test/jalview/bin/argparser/testfiles/argfile0.txt" },
165 { "--argfile=test/jalview/bin/argparser/testfiles/argfile*.txt",
167 "test/jalview/bin/argparser/testfiles/argfile1.txt" },
168 { "--argfile=test/jalview/bin/argparser/testfiles/argfile*.txt",
170 "test/jalview/bin/argparser/testfiles/argfile2.txt" } };
173 @DataProvider(name = "argSubValsAndLinkedIds")
174 public Object[][] argSubValsAndLinkedIds()
176 return new Object[][] { {
177 "--debug --open=[hi]test/jalview/bin/argparser/testfiles/test1.fa",
178 "JALVIEW:0", Arg.OPEN, "hi", "true", true },
179 { "--open[linkedId1]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless",
180 "linkedId1", Arg.OPEN, "new", "true", true },
181 { "--open[linkedId2]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless",
182 "linkedId2", Arg.OPEN, "hello", "world", true },
183 { "--open[linkedId3]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless",
184 "linkedId3", Arg.OPEN, "GETINDEX", "1", true },
185 { "--open[linkedId4]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId5]=[notnew;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless",
186 "linkedId5", Arg.OPEN, "new", "true", false },
187 { "--open[linkedId5]=[new;hello=worlddomination;1]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId2]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless",
188 "linkedId5", Arg.OPEN, "hello", "world", false },
189 { "--open[linkedId6]=[new;hello=world;0]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId7]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless",
190 "linkedId7", Arg.OPEN, "GETINDEX", "0", false }, };
193 @DataProvider(name = "argAutoIndexAndSubstitutions")
194 public Object[][] argAutoIndexAndSubstitutions()
196 return new Object[][] { { "--open=filename0 --open=filename1",
197 "JALVIEW:0", Arg.OPEN, "filename0" },
198 { "--open=filename0 --increment --open=filename1", "JALVIEW:1",
199 Arg.OPEN, "filename1" },
200 { "--open=filename0 --increment --increment --open=filename2",
201 "JALVIEW:0", Arg.OPEN, "filename0" },
202 { "--open=filename0 --increment --increment --open=filename2",
203 "JALVIEW:2", Arg.OPEN, "filename2" },
204 { "--open[linkA-{n}]=filenameA0 --open[linkA-{++n}]=filenameA1",
205 "linkA-0", Arg.OPEN, "filenameA0" },
206 { "--open[linkB-{n}]=filenameB0 --open[linkB-{++n}]=filenameB1",
207 "linkB-1", Arg.OPEN, "filenameB1" },
208 { "--open[linkC-{n}]=filenameC0 --image[linkC-{n}]=outputC{n}.txt",
209 "linkC-0", Arg.IMAGE, "outputC{n}.txt" },
210 { "--open[linkD-{n}]=filenameD0 --substitutions --image[linkD-{n}]=outputD{n}.txt",
211 "linkD-0", Arg.IMAGE, "outputD0.txt" },
212 { "--open[linkE-{n}]=filenameE0 --substitutions --image[linkE-{n}]=output-E{n}.txt --nil[{++n}] --image[linkE-{n}]=outputE{n}.txt",
213 "linkE-0", Arg.IMAGE, "output-E0.txt" },
214 { "--open[linkF-{n}]=filenameF0 --substitutions --image[linkF-{n}]=output-F{n}.txt --nil[{++n}] --image[linkF-{n}]=outputF{n}.txt",
215 "linkF-1", Arg.IMAGE, "outputF1.txt" },
216 { "--open[linkG-{n}]=filenameG0 --substitutions --image[linkG-{n}]=output-G{n}.txt --nil[{++n}] --nosubstitutions --image[linkG-{n}]=outputG{n}.txt",
217 "linkG-1", Arg.IMAGE, "outputG{n}.txt" },
218 { "--open[linkH-{n}]=filenameH0 --substitutions --image[linkH-{n}]=output-H{n}.txt --nil[{++n}] --nosubstitutions --image[linkH-{n}]=outputH{n}.txt",
219 "linkH-0", Arg.IMAGE, "output-H0.txt" }, };
222 @DataProvider(name = "argFiles")
223 public Object[][] argFiles()
225 return new Object[][] { {
226 "--argfile=test/jalview/bin/argparser/testfiles/argfile0.txt --open=shouldntbeabootstrap",
227 Arg.ARGFILE, "test/jalview/bin/argfiles/testfiles/test1.fa" } };