Example #1
0
  @Before
  public void setUp() throws Throwable {
    // Filter disabled tests
    assumeTrue(test.isEnabled());

    String fileContent = test.readFile();
    if (!test.isValidTest(isStrictTest, unmarkedDefault)) {
      return;
    }

    final String preamble;
    if (test.isRaw()) {
      preamble = "";
      preambleLines = 0;
    } else if (isStrictTest) {
      preamble = "\"use strict\";\nvar strict_mode = true;\n";
      preambleLines = 2;
    } else {
      preamble = "//\"use strict\";\nvar strict_mode = false;\n";
      preambleLines = 2;
    }
    sourceCode = Strings.concat(preamble, fileContent);

    global = globals.newGlobal(new Test262Console(), test);
    exceptionHandler.setExecutionContext(global.getRealm().defaultContext());

    if (!test.isNegative()) {
      errorHandler.match(StandardErrorHandler.defaultMatcher());
      exceptionHandler.match(ScriptExceptionHandler.defaultMatcher());
    } else {
      expected.expect(
          Matchers.either(StandardErrorHandler.defaultMatcher())
              .or(ScriptExceptionHandler.defaultMatcher())
              .or(instanceOf(Test262AssertionError.class)));
      String errorType = test.getErrorType();
      if (errorType != null) {
        expected.expect(
            hasErrorMessage(
                global.getRealm().defaultContext(),
                matchesPattern(errorType, Pattern.CASE_INSENSITIVE)));
      }
    }

    // Load test includes
    for (String name : test.getIncludes()) {
      global.include(name);
    }

    if (test.isAsync()) {
      // "doneprintHandle.js" is replaced with AsyncHelper
      async = global.install(new AsyncHelper(), AsyncHelper.class);
    }

    // Install test hooks
    if (!test.getScript().startsWith(selfTestDirectory)) {
      global.install(global, Test262GlobalObject.class);
    }
  }
Example #2
0
  @Test
  public void runTest() throws Throwable {
    if (!test.isValidTest(isStrictTest, unmarkedDefault)) {
      return;
    }
    // Evaluate actual test-script
    if (test.isModule()) {
      global.evalModule(test.toModuleName(), sourceCode, 1 - preambleLines);
    } else {
      global.eval(test.toFile(), sourceCode, 1 - preambleLines);
    }

    // Wait for pending tasks to finish
    if (test.isAsync()) {
      assertFalse(async.doneCalled);
      global.getRealm().getWorld().runEventLoop();
      assertTrue(async.doneCalled);
    } else {
      global.getRealm().getWorld().runEventLoop();
    }
  }
Example #3
0
  @Before
  public void setUp() throws Throwable {
    assumeTrue("Test disabled", test.isEnabled());

    String fileContent = test.readFile();
    if (!isValidTestConfiguration()) {
      return;
    }

    final String preamble;
    if (test.isRaw() || test.isModule()) {
      preamble = "";
      preambleLines = 0;
    } else if (isStrictTest) {
      preamble = "\"use strict\";\nvar strict_mode = true;\n";
      preambleLines = 2;
    } else {
      preamble = "//\"use strict\";\nvar strict_mode = false;\n";
      preambleLines = 2;
    }
    sourceCode = Strings.concat(preamble, fileContent);

    global = globals.newGlobal(new Test262Console(), test);
    exceptionHandler.setExecutionContext(global.getRealm().defaultContext());

    if (!test.isNegative()) {
      errorHandler.match(StandardErrorHandler.defaultMatcher());
      exceptionHandler.match(ScriptExceptionHandler.defaultMatcher());
    } else {
      expected.expect(
          Matchers.either(StandardErrorHandler.defaultMatcher())
              .or(ScriptExceptionHandler.defaultMatcher()));
      String errorType = test.getErrorType();
      if (errorType != null) {
        expected.expect(
            hasErrorMessage(
                global.getRealm().defaultContext(),
                matchesPattern(errorType, Pattern.CASE_INSENSITIVE)));
      }
    }

    // Load test includes
    for (String name : test.getIncludes()) {
      global.include(name);
    }

    if (test.isAsync()) {
      async = global.install(new Test262Async(), Test262Async.class);
    }
  }
Example #4
0
 private boolean isValidTestConfiguration() {
   return test.hasMode(isStrictTest, unmarkedDefault)
       && test.hasFeature(includeFeatures, excludeFeatures);
 }