Ejemplo n.º 1
0
  private void run(String[] programArgs, String expectedOutput, String expectedError)
      throws IOException, ConfigurationException, InterruptedException {

    // Should be initialized at this point by call to Main.run()
    Configuration config = Configuration.getConfiguration();

    Path fullExecutable = config.getSystemImport().resolve(executable);

    List<String> programCommand = new ArrayList<String>();
    programCommand.add(fullExecutable.toAbsolutePath().toString());

    for (String arg : programArgs) programCommand.add(arg);

    Process program = new ProcessBuilder(programCommand).start();

    // regular output
    BufferedReader reader = new BufferedReader(new InputStreamReader(program.getInputStream()));
    BufferedReader errorReader =
        new BufferedReader(new InputStreamReader(program.getErrorStream()));
    StringBuilder builder = new StringBuilder();
    String line;
    do {
      line = reader.readLine();
      if (line != null) builder.append(line).append('\n');
    } while (line != null);
    String output = builder.toString();
    assertEquals(expectedOutput, output);

    // error output
    builder = new StringBuilder();
    do {
      line = errorReader.readLine();
      if (line != null) builder.append(line).append('\n');
    } while (line != null);

    String error = builder.toString();
    assertEquals(expectedError, error);

    program.waitFor(); // keeps program from being deleted while running
  }
Ejemplo n.º 2
0
 /**
  * Creates a new <code>TypeCollector</code> with the given tree of packages.
  *
  * @param p package tree
  * @param useSourceFiles if true, always use <tt>.shadow</tt> instead of <tt>.meta</tt> files
  * @throws ConfigurationException
  */
 public TypeCollector(Package p, boolean useSourceFiles) throws ConfigurationException {
   super(p);
   this.useSourceFiles = useSourceFiles;
   config = Configuration.getConfiguration();
 }