Cleanup and calling the VMTest.read method directly launcher
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 17 Dec 2012 17:51:05 +0100
branchlauncher
changeset 3476f964a88e6c5
parent 346 b671ac44bc55
child 348 4e9d576780ca
Cleanup and calling the VMTest.read method directly
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java
     1.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java	Mon Dec 17 17:45:08 2012 +0100
     1.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/VMTest.java	Mon Dec 17 17:51:05 2012 +0100
     1.3 @@ -55,7 +55,7 @@
     1.4      }
     1.5  
     1.6      /** Inspects <code>clazz</code> and for each {@lik Compare} method creates
     1.7 -     * instances of tests. Each insteance runs the test in different virtual
     1.8 +     * instances of tests. Each instance runs the test in different virtual
     1.9       * machine and at the end they compare the results.
    1.10       * 
    1.11       * @param clazz the class to inspect
    1.12 @@ -140,7 +140,7 @@
    1.13          Object value;
    1.14          private Invocable code;
    1.15          private CharSequence codeSeq;
    1.16 -        private static final Map<Class,Object[]> compiled = new WeakHashMap<Class,Object[]>();
    1.17 +        private static final Map<Class,Object[]> compiled = new WeakHashMap<>();
    1.18  
    1.19          private Run(Method m, boolean js) {
    1.20              this.m = m;
    1.21 @@ -158,17 +158,16 @@
    1.22              Bck2Brwsr.generate(sb, VMTest.class.getClassLoader());
    1.23  
    1.24              ScriptEngineManager sem = new ScriptEngineManager();
    1.25 -            ScriptEngine js = sem.getEngineByExtension("js");
    1.26 +            ScriptEngine mach = sem.getEngineByExtension("js");
    1.27              
    1.28 -            sb.append("\nfunction initVM() {"
    1.29 -                + "\n  return bck2brwsr("
    1.30 -                + "\n    function(name) { return org.apidesign.bck2brwsr.vmtest.VMTest.read(name);}"
    1.31 -                + "\n  );"
    1.32 -                + "\n};");
    1.33 +            sb.append(
    1.34 +                  "\nvar vm = bck2brwsr(org.apidesign.bck2brwsr.vmtest.VMTest.read);"
    1.35 +                + "\nfunction initVM() { return vm; };"
    1.36 +                + "\n");
    1.37  
    1.38 -            Object res = js.eval(sb.toString());
    1.39 -            Assert.assertTrue(js instanceof Invocable, "It is invocable object: " + res);
    1.40 -            code = (Invocable) js;
    1.41 +            Object res = mach.eval(sb.toString());
    1.42 +            Assert.assertTrue(mach instanceof Invocable, "It is invocable object: " + res);
    1.43 +            code = (Invocable) mach;
    1.44              codeSeq = sb;
    1.45              compiled.put(clazz, new Object[] { code, codeSeq });
    1.46          }
    1.47 @@ -246,9 +245,9 @@
    1.48      
    1.49      static StringBuilder dumpJS(CharSequence sb) throws IOException {
    1.50          File f = File.createTempFile("execution", ".js");
    1.51 -        FileWriter w = new FileWriter(f);
    1.52 -        w.append(sb);
    1.53 -        w.close();
    1.54 +        try (FileWriter w = new FileWriter(f)) {
    1.55 +            w.append(sb);
    1.56 +        }
    1.57          return new StringBuilder(f.getPath());
    1.58      }
    1.59  }