示例#1
0
 /**
  * Main testing method that runs the test based on the passed test spec.
  *
  * @param testSpec Test-specific routines (providing encoding/decoding streams).
  * @throws IOException I/O exception.
  */
 protected void test(TestSpec testSpec) throws IOException {
   byte[] entity = "Hello world!".getBytes();
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   OutputStream encoded = testSpec.getEncoded(baos);
   encoded.write(entity);
   encoded.close();
   ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
   byte[] result = new byte[entity.length];
   InputStream decoded = testSpec.getDecoded(bais);
   int len = decoded.read(result);
   assertEquals(-1, decoded.read());
   decoded.close();
   assertEquals(entity.length, len);
   assertArrayEquals(entity, result);
 }
  private static void append(final StringBuilder sb, final TestSpec spec) {
    TestSpecDescription desc = spec.getDescription();

    String text =
        StringUtil.replaceAll(desc.getText().replaceAll(Pattern.quote("\n"), "<br>"), "  ", " ")
            .replaceAll(Pattern.quote("<br> "), "<br>");
    sb.append(desc.getUsed());
    sb.append(" | ");
    sb.append(desc.getUsedBy());
    sb.append(" | ");
    sb.append(desc.getChange());
    sb.append(" | ");
    sb.append(spec.getResult());
    sb.append(" | ");
    sb.append(text);
    sb.append("\n");
  }
示例#3
0
 /**
  * This is for troubleshooting suite failures by running a subset of tests within a suite without
  * requiring any Java or Gosu code changes
  */
 private void restrictTestSpecsToSpecifiedNames() {
   String includedTests = System.getProperty(GOSU_SUITE_INCLUDE_TYPES);
   if (includedTests != null) {
     System.out.println(
         "System property "
             + GOSU_SUITE_INCLUDE_TYPES
             + " used, so only running tests specified:");
     System.out.println(includedTests);
     String[] includedTestsArray = includedTests.replace(" ", "").split(",");
     HashSet<String> includedTestSet = new HashSet<String>(Arrays.asList(includedTestsArray));
     for (Iterator<TestSpec> it = _testSpecs.iterator(); it.hasNext(); ) {
       TestSpec spec = it.next();
       if (!includedTestSet.contains(spec.getTestType().getName())) {
         it.remove();
       }
     }
   }
 }
示例#4
0
  private void maybeCreateTestClassWrappers() {

    maybeInitSuite();

    if (!_testClassWrappersCreated) {
      long start = System.currentTimeMillis();

      if (_testSpecs.isEmpty()) {
        TestClassFinder finder =
            new TestClassFinder(_iFileFilters, _packageFilters, _withPackages, _typeFilters);
        _testSpecs.addAll(finder.findTests(_gosuClassSearchPath, _javaClassSearchPath));
      }

      restrictTestSpecsToSpecifiedNames();

      for (TestSpec spec : _testSpecs) {
        if (_testEnvironment.isRemoteExecutionEnvironment()) {
          String[] methods = spec.runAllMethods() ? null : spec.getMethods();
          RemoteTestClassWrapper remoteWrapper =
              new RemoteTestClassWrapper(_executionManager, spec.getTestTypeName(), methods);
          addTest(remoteWrapper);
        } else {
          IType type = spec.getTestType();
          addTest(new TestClassWrapper(_executionManager, type, spec.getMethods()));
        }
      }
      _testClassWrappersCreated = true;
      long end = System.currentTimeMillis();
      System.out.println("Test wrappers created in " + (end - start) + "ms");

      if (_testEnvironment.isDynamicallyDeterminedEnvironment()) {
        _testEnvironment = determineTestEnvironmentBasedOnTestDefaults();
        System.out.println(
            "Dynamically determined the test environment to be " + _testEnvironment.getClass());
        // This is pretty hacky, but RemoteTestEnvironments need a chance to tell the remote server
        // what sort of environment to set up, and that actually needs to be done prior to beginning
        // the suite
        if (_testEnvironment instanceof ForwardingTestEnvironment) {
          _testEnvironment.initializeTypeSystem();
        }
        _executionManager.setEnvironment(_testEnvironment);
      }
    }
  }
  @Test
  public void all() throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append("# Tests\n");
    sb.append("Used | Used By | Change | Result | Description\n");
    sb.append("---- | ------- | ------ | ------ | -----------\n");

    for (TestSpecs spec : TestSpecs.values()) {
      append(sb, TestSpec.parse(spec.toString()));
    }
    sb.append("\n");
    sb.append("Page generated on ");
    sb.append(new Date());
    sb.append("\n");

    File dir = new File(".").getCanonicalFile().getParentFile().getParentFile();
    File md = new File(dir, "TESTS.md");
    FileOutputStream out = new FileOutputStream(md);
    try {
      out.write(sb.toString().getBytes("US-ASCII"));
    } finally {
      DisposeUtil.closeUnsafe(out);
    }
  }