FleetProcess.java: add masterClear() method, use it in Main.java
authorAdam Megacz <adam@megacz.com>
Sun, 20 Sep 2009 19:34:32 +0000 (12:34 -0700)
committerAdam Megacz <adam@megacz.com>
Sun, 20 Sep 2009 19:34:32 +0000 (12:34 -0700)
src/edu/berkeley/fleet/Main.java
src/edu/berkeley/fleet/api/FleetProcess.java

index 885e0c1..aee832d 100644 (file)
@@ -70,15 +70,20 @@ public class Main {
             pw.close();
 
         } else if (command.equals("test")) {
-            for(int i=0; i<args.size(); i++)
-                test(fleet, new File(args.get(i)));
+            FleetProcess fp = fleet.run(null);
+            try {
+                for(int i=0; i<args.size(); i++)
+                    test(fleet, fp, new File(args.get(i)));
+            } finally {
+                fp.terminate();
+            }
         } else {
             usage();
             System.exit(-1);
         }
     }
 
-    static void runTest(Fleet fleet, Reader reader, String title) throws Exception {
+    static void runTest(Fleet fleet, FleetProcess fp, Reader reader, String title) throws Exception {
         Instruction[] instructions = null;
         System.out.print("\r[    ] "  + ANSI.yellow(title)+": ");
         try {
@@ -93,9 +98,11 @@ public class Main {
             edu.berkeley.fleet.assembler.Parser.skip = false;
             return;
         }
-        FleetProcess fp = fleet.run(instructions);
+        fp.masterClear();
+        for(Instruction i : instructions)
+            fp.sendInstruction(i);
         //long now = System.currentTimeMillis();
-        try {
+
             ArrayList<Long> expect = edu.berkeley.fleet.assembler.Parser.expect;
             String output = "";
             // FIXME: check for extraneous stuff at the end
@@ -132,18 +139,15 @@ public class Main {
                 }
             }
             System.out.println();
-        } finally {
-            fp.terminate();
-        }
     }
 
-    static void test(Fleet fleet, File f) throws Exception {
+    static void test(Fleet fleet, FleetProcess fp, File f) throws Exception {
         if (f.isDirectory()) {
             for(String s : f.list())
-                test(fleet, new File(f.getPath() + File.separatorChar + s));
+                test(fleet, fp, new File(f.getPath() + File.separatorChar + s));
             return;
         } else if (f.getPath().endsWith(".fleet") || f.getPath().endsWith(".test")) {
-            runTest(fleet, new InputStreamReader(new FileInputStream(f)), f.getPath());
+            runTest(fleet, fp, new InputStreamReader(new FileInputStream(f)), f.getPath());
         } else if (f.getPath().endsWith(".ship")) {
             ShipDescription sd = new ShipDescription(fleet, f.getName(), new BufferedReader(new InputStreamReader(new FileInputStream(f))));
             String testsection = sd.getSection("test");
@@ -152,7 +156,7 @@ public class Main {
             else if (fleet.getShip(sd.getName(),0)==null && !(fleet instanceof edu.berkeley.fleet.assembler.Parser.FleetWithDynamicShips))
                 System.out.println("specified Fleet does not have any ships of type " + sd.getName());
             else
-                runTest(fleet, new StringReader(testsection), sd.getName());
+                runTest(fleet, fp, new StringReader(testsection), sd.getName());
         }
     }
 
index c232405..2dd7332 100644 (file)
@@ -50,6 +50,8 @@ public abstract class FleetProcess {
     /** Terminate the process; subclasses may be assured that this will be called exactly once. */
     protected abstract void _terminate();
 
+    public void masterClear() { throw new RuntimeException("not implemented"); }
+
     /** Terminate the process. */
     public final synchronized void terminate() {
         if (terminated) return;