run(fleet, is);
} else if (command.equals("expand")) {
- fleet.expand(new ShipDescription(new BufferedReader(new InputStreamReader(new FileInputStream(args.get(0))))));
+ fleet.expand(new ShipDescription(args.get(0), new BufferedReader(new InputStreamReader(new FileInputStream(args.get(0))))));
} else if (command.equals("doc")) {
Doc.print();
}
}
+ static void runTest(Fleet fleet, Reader reader, String title) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ edu.berkeley.fleet.assembler.Main.assemble(fleet, reader, baos);
+ if (edu.berkeley.fleet.assembler.Parser.skip) {
+ System.out.println("\r[" + ANSI.yellow("SKIP") +
+ "] " + ANSI.yellow(title));
+ return;
+ }
+ FleetProcess fp = fleet.run(baos.toByteArray());
+ try {
+ ArrayList<Long> expect = edu.berkeley.fleet.assembler.Parser.expect;
+ String output = "";
+ // FIXME: check for extraneous stuff at the end
+ String verdict = "[ ]";
+ boolean failed = false;
+ while(true) {
+ if (output.length() > 60 && !failed)
+ output = "..."+output.substring(output.length()-57, output.length());
+ if (expect.size() == 0) verdict = "["+ANSI.green("PASS")+"]";
+ System.out.print("\r" + verdict + " " + ANSI.yellow(title) + ": " + output);
+ if (failed) break;
+ if (expect.size() == 0) break;
+ long l = fp.readWord();
+ long l2 = expect.remove(0);
+ if (l!=l2) {
+ verdict = "["+ANSI.red("FAIL")+"]";
+ output += ANSI.red("0x"+Long.toString(l, 16)) +
+ ANSI.yellow(" (expected ")+ANSI.green("0x"+Long.toString(l2, 16))+ANSI.yellow(")");
+ failed = true;
+ continue;
+ } else {
+ output += ("0x"+Long.toString(l2, 16) + " ");
+ }
+ }
+ System.out.println();
+ } finally {
+ fp.terminate();
+ }
+ }
+
static void test(Fleet fleet, File f) throws Exception {
if (f.isDirectory()) {
for(String s : f.list())
test(fleet, new File(f.getPath() + File.separatorChar + s));
+ return;
} else if (f.getPath().endsWith(".fleet")) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- edu.berkeley.fleet.assembler.Main.assemble(fleet, new InputStreamReader(new FileInputStream(f)), baos);
- if (edu.berkeley.fleet.assembler.Parser.skip) {
- System.out.println("\r[" + ANSI.yellow("SKIP") +
- "] " + ANSI.yellow(f.getPath()));
- return;
- }
- FleetProcess fp = fleet.run(baos.toByteArray());
- try {
- ArrayList<Long> expect = edu.berkeley.fleet.assembler.Parser.expect;
- String output = "";
- // FIXME: check for extraneous stuff at the end
- String verdict = "[ ]";
- boolean failed = false;
- while(true) {
- if (output.length() > 60 && !failed)
- output = "..."+output.substring(output.length()-57, output.length());
- if (expect.size() == 0) verdict = "["+ANSI.green("PASS")+"]";
- System.out.print("\r" + verdict + " " + ANSI.yellow(f.getPath()) + ": " + output);
- if (failed) break;
- if (expect.size() == 0) break;
- long l = fp.readWord();
- long l2 = expect.remove(0);
- if (l!=l2) {
- verdict = "["+ANSI.red("FAIL")+"]";
- output += ANSI.red("0x"+Long.toString(l, 16)) +
- ANSI.yellow(" (expected ")+ANSI.green("0x"+Long.toString(l2, 16))+ANSI.yellow(")");
- failed = true;
- continue;
- } else {
- output += ("0x"+Long.toString(l2, 16) + " ");
- }
- }
- System.out.println();
- } finally {
- fp.terminate();
- }
+ runTest(fleet, new InputStreamReader(new FileInputStream(f)), f.getPath());
+ } else if (f.getPath().endsWith(".ship")) {
+ ShipDescription sd = new ShipDescription(f.getName(), new BufferedReader(new InputStreamReader(new FileInputStream(f))));
+ runTest(fleet, new StringReader(sd.getSection("test")), sd.getName());
}
}
public String getSection(String sectionName) { return sections.get(sectionName); }
public Iterator<BenkoBoxDescription> iterator() { return benkoBoxes.iterator(); }
- public ShipDescription(BufferedReader r) throws IOException {
- String sectionName = "";
+ public ShipDescription(String name, BufferedReader r) throws IOException {
+ if (name.endsWith(".ship"))
+ name = name.substring(0, name.length() - ".ship".length());
+ while(name.indexOf('/') != -1) name = name.substring(name.indexOf('/')+1);
+ this.name = name;
+ String sectionName = null;
StringBuffer sb = new StringBuffer();
while(true) {
String s = r.readLine();
- if (s==null) break;
- if (s.startsWith("==")) {
- sections.put(sectionName, sb.toString());
+ if (s==null || s.startsWith("==")) {
+ if (sectionName != null) sections.put(sectionName, sb.toString());
+ if (s==null) break;
sb = new StringBuffer();
sectionName = s.trim();
while(sectionName.startsWith("="))