test/src/jdk/nashorn/internal/codegen/CompilerTest.java

Print this page




  26 package jdk.nashorn.internal.codegen;
  27 
  28 import java.io.File;
  29 import java.io.PrintWriter;
  30 import java.io.StringWriter;
  31 import jdk.nashorn.internal.runtime.Context;
  32 import jdk.nashorn.internal.runtime.ErrorManager;
  33 import jdk.nashorn.internal.runtime.ScriptFunction;
  34 import jdk.nashorn.internal.runtime.ScriptObject;
  35 import jdk.nashorn.internal.runtime.Source;
  36 import jdk.nashorn.internal.runtime.options.Options;
  37 import org.testng.Assert;
  38 import org.testng.annotations.Test;
  39 
  40 /**
  41  * Tests to check Nashorn JS compiler - just compiler and not execution of scripts.
  42  */
  43 public class CompilerTest {
  44     private static final boolean VERBOSE  = Boolean.valueOf(System.getProperty("compilertest.verbose"));
  45     private static final boolean TEST262  = Boolean.valueOf(System.getProperty("compilertest.test262"));
  46 
  47     private static final String ES5CONFORM_DIR    = System.getProperty("es5conform.testcases.dir");
  48     private static final String TEST_BASIC_DIR  = System.getProperty("test.basic.dir");
  49     private static final String TEST262_SUITE_DIR = System.getProperty("test262.suite.dir");
  50 
  51     interface TestFilter {
  52         public boolean exclude(File file, String content);
  53     }
  54 
  55     private void log(String msg) {
  56         org.testng.Reporter.log(msg, true);
  57     }
  58 
  59     private Context context;
  60     private ScriptObject global;
  61 
  62     public CompilerTest() {
  63         final Options options = new Options("nashorn");
  64         options.set("anon.functions", true);
  65         options.set("compile.only", true);
  66         options.set("print.ast", true);
  67         options.set("print.parse", true);


  73                 log(msg);
  74             }
  75         };
  76 
  77         final StringWriter sw = new StringWriter();
  78         final PrintWriter pw = new PrintWriter(sw);
  79         this.context = new Context(options, errors, pw, pw);
  80         this.global = context.createGlobal();
  81     }
  82 
  83     @Test
  84     public void compileAllTests() {
  85         if (TEST262) {
  86             compileTestSet(TEST262_SUITE_DIR, new TestFilter() {
  87                 @Override
  88                 public boolean exclude(final File file, final String content) {
  89                     return content.indexOf("@negative") != -1;
  90                 }
  91             });
  92         }
  93         compileTestSet(ES5CONFORM_DIR, null);
  94         compileTestSet(TEST_BASIC_DIR, null);
  95     }
  96 
  97     private void compileTestSet(final String testSet, final TestFilter filter) {
  98         passed = 0;
  99         failed = 0;
 100         skipped = 0;
 101         final File testSetDir = new File(testSet);
 102         if (! testSetDir.isDirectory()) {
 103             log("WARNING: " + testSetDir + " not found or not a directory");
 104             return;
 105         }
 106         log(testSetDir.getAbsolutePath());
 107         compileJSDirectory(testSetDir, filter);
 108 
 109         log(testSet + " compile done!");
 110         log("compile ok: " + passed);
 111         log("compile failed: " + failed);
 112         log("compile skipped: " + skipped);
 113         if (failed != 0) {




  26 package jdk.nashorn.internal.codegen;
  27 
  28 import java.io.File;
  29 import java.io.PrintWriter;
  30 import java.io.StringWriter;
  31 import jdk.nashorn.internal.runtime.Context;
  32 import jdk.nashorn.internal.runtime.ErrorManager;
  33 import jdk.nashorn.internal.runtime.ScriptFunction;
  34 import jdk.nashorn.internal.runtime.ScriptObject;
  35 import jdk.nashorn.internal.runtime.Source;
  36 import jdk.nashorn.internal.runtime.options.Options;
  37 import org.testng.Assert;
  38 import org.testng.annotations.Test;
  39 
  40 /**
  41  * Tests to check Nashorn JS compiler - just compiler and not execution of scripts.
  42  */
  43 public class CompilerTest {
  44     private static final boolean VERBOSE  = Boolean.valueOf(System.getProperty("compilertest.verbose"));
  45     private static final boolean TEST262  = Boolean.valueOf(System.getProperty("compilertest.test262"));


  46     private static final String TEST_BASIC_DIR  = System.getProperty("test.basic.dir");
  47     private static final String TEST262_SUITE_DIR = System.getProperty("test262.suite.dir");
  48 
  49     interface TestFilter {
  50         public boolean exclude(File file, String content);
  51     }
  52 
  53     private void log(String msg) {
  54         org.testng.Reporter.log(msg, true);
  55     }
  56 
  57     private Context context;
  58     private ScriptObject global;
  59 
  60     public CompilerTest() {
  61         final Options options = new Options("nashorn");
  62         options.set("anon.functions", true);
  63         options.set("compile.only", true);
  64         options.set("print.ast", true);
  65         options.set("print.parse", true);


  71                 log(msg);
  72             }
  73         };
  74 
  75         final StringWriter sw = new StringWriter();
  76         final PrintWriter pw = new PrintWriter(sw);
  77         this.context = new Context(options, errors, pw, pw);
  78         this.global = context.createGlobal();
  79     }
  80 
  81     @Test
  82     public void compileAllTests() {
  83         if (TEST262) {
  84             compileTestSet(TEST262_SUITE_DIR, new TestFilter() {
  85                 @Override
  86                 public boolean exclude(final File file, final String content) {
  87                     return content.indexOf("@negative") != -1;
  88                 }
  89             });
  90         }

  91         compileTestSet(TEST_BASIC_DIR, null);
  92     }
  93 
  94     private void compileTestSet(final String testSet, final TestFilter filter) {
  95         passed = 0;
  96         failed = 0;
  97         skipped = 0;
  98         final File testSetDir = new File(testSet);
  99         if (! testSetDir.isDirectory()) {
 100             log("WARNING: " + testSetDir + " not found or not a directory");
 101             return;
 102         }
 103         log(testSetDir.getAbsolutePath());
 104         compileJSDirectory(testSetDir, filter);
 105 
 106         log(testSet + " compile done!");
 107         log("compile ok: " + passed);
 108         log("compile failed: " + failed);
 109         log("compile skipped: " + skipped);
 110         if (failed != 0) {