Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
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);
    }
  }