示例#1
0
  public void runNext() throws TestFailException, UnsupportedEncodingException {
    // Get first file and remove it from list
    InputOutput current = inputOutput.remove(0);
    // Create List with only first input in
    List<String> inputFiles = new ArrayList<String>();
    inputFiles.add(null != commonInputFile ? commonInputFile : current.getName() + ".input");
    // Excute Main on that input
    List<String> cmdLine = new ArrayList<String>();
    cmdLine.add("--encoding");
    cmdLine.add(inputFileEncoding);
    classExecResult =
        Exec.execClass(
            className,
            testPath.toString(),
            cmdLine,
            inputFiles,
            Main.jflexTestVersion,
            outputFileEncoding);
    if (Main.verbose) {
      System.out.println("Running scanner on [" + current.getName() + "]");
    }

    // check for output conformance
    File expected = new File(current.getName() + ".output");

    if (expected.exists()) {
      DiffStream check = new DiffStream();
      String diff;
      try {
        diff =
            check.diff(
                jflexDiff,
                new StringReader(classExecResult.getOutput()),
                new InputStreamReader(new FileInputStream(expected), outputFileEncoding));
      } catch (FileNotFoundException e) {
        System.out.println("Error opening file " + expected);
        throw new TestFailException();
      } catch (UnsupportedEncodingException e) {
        System.out.println("Unsupported encoding '" + outputFileEncoding + "'");
        throw new TestFailException();
      }
      if (diff != null) {
        System.out.println("Test failed, unexpected output: " + diff);
        System.out.println("Test output: " + classExecResult.getOutput());
        throw new TestFailException();
      }
    } else {
      System.out.println("Warning: no file for expected output [" + expected + "]");
    }

    // System.out.println(classExecResult);
  }
示例#2
0
  public void createScanner() throws TestFailException {
    jflexFiles.add((new File(testPath, testName + ".flex")).getPath());
    // invoke JFlex
    jflexResult = Exec.execJFlex(jflexCmdln, jflexFiles);
    // System.out.println(jflexResult);

    if (jflexResult.getSuccess()) {
      // Scanner generation successful
      if (Main.verbose) {
        System.out.println("Scanner generation successful");
      }

      if (expectJFlexFail) {
        System.out.println("JFlex failure expected!");
        throw new TestFailException();
      }

      // check JFlex output conformance
      File expected = new File(testPath, testName + "-flex.output");

      if (expected.exists()) {
        DiffStream check = new DiffStream();
        String diff;
        try {
          diff =
              check.diff(
                  jflexDiff, new StringReader(jflexResult.getOutput()), new FileReader(expected));
        } catch (FileNotFoundException e) {
          System.out.println("Error opening file " + expected);
          throw new TestFailException();
        }
        if (diff != null) {
          System.out.println("Test failed, unexpected jflex output: " + diff);
          System.out.println("JFlex output: " + jflexResult.getOutput());
          throw new TestFailException();
        }
      } else {
        System.out.println("Warning: no file for expected output [" + expected + "]");
      }

      // Compile Scanner
      String toCompile = new File(testPath, className + ".java").getPath();
      if (Main.verbose) {
        System.out.println("File to Compile: " + toCompile);
      }
      javacFiles.add(toCompile);
      javacResult = Exec.execJavac(testPath, Main.jflexTestVersion);

      // System.out.println(javacResult);
      if (Main.verbose) {
        System.out.println(
            "Compilation successful: "
                + javacResult.getSuccess()
                + " [expected: "
                + !expectJavacFail
                + "]");
      }
      if (javacResult.getSuccess() == expectJavacFail) {
        System.out.println("Compilation failed, messages:");
        System.out.println(javacResult.getOutput());
        throw new TestFailException();
      }
    } else {
      if (!expectJFlexFail) {
        System.out.println("Scanner generation failed!");
        System.out.println("JFlex output was:\n" + jflexResult.getOutput());
        throw new TestFailException();
      } else {
        // check JFlex output conformance
        File expected = new File(testPath, testName + "-flex.output");

        if (expected.exists()) {
          DiffStream check = new DiffStream();
          String diff;
          try {
            diff =
                check.diff(
                    jflexDiff, new StringReader(jflexResult.getOutput()), new FileReader(expected));
          } catch (FileNotFoundException e) {
            System.out.println("Error opening file " + expected);
            throw new TestFailException();
          }
          if (diff != null) {
            System.out.println("Test failed, unexpected jflex output: " + diff);
            System.out.println("JFlex output: " + jflexResult.getOutput());
            throw new TestFailException();
          }
        }
      }
    }
  }