Exemple #1
0
  private static void walkTests(List<String> args, boolean verbose)
      throws UserError, IOException, Throwable {
    boolean _verbose = verbose;
    if (args.size() == 0) {
      throw new UserError("Need a file to run through the Fortress interpreter.");
    }
    String s = args.get(0);
    List<String> rest = args.subList(1, args.size());

    if (s.startsWith("-")) {
      if (s.equals("-debug")) {
        rest = Debug.parseOptions(rest);
      } else if (s.equals("-verbose")) {
        _verbose = true;
      } else invalidFlag(s, "test");
      walkTests(rest, _verbose);
    } else {
      for (String file : args) {
        try {
          Iterable<? extends StaticError> errors = IterUtil.empty();
          try {
            if (!isComponent(file)) throw new UserError(file + " is not a component file.");
            APIName name = NodeUtil.apiName(file);
            Path path = sourcePath(file, name);
            GraphRepository bcr = specificInterpreterRepository(path);
            ComponentIndex cu = bcr.getLinkedComponent(name);
            Driver.runTests(bcr, cu, _verbose);
          } catch (Throwable th) {
            // TODO FIXME what is the proper treatment of errors/exceptions etc.?
            if (th instanceof FortressException) {
              FortressException pe = (FortressException) th;
              if (pe.getStaticErrors() != null) errors = pe.getStaticErrors();
            }
            if (th instanceof RuntimeException) throw (RuntimeException) th;
            if (th instanceof Error) throw (Error) th;
            throw new WrappedException(th, Debug.stackTraceOn());
          }

          for (StaticError error : errors) {
            System.err.println(error);
          }
          // If there are no errors,
          // all components will have been written to disk
          // by the CacheBasedRepository.
        } catch (StaticError e) {
          System.err.println(e);
          if (Debug.stackTraceOn()) {
            e.printStackTrace();
          }
        } catch (RepositoryError e) {
          System.err.println(e.getMessage());
        } catch (FortressException e) {
          failureBoilerplate(e);
          System.exit(1);
        }
      }
    }
  }
Exemple #2
0
 /** @param e */
 private static void failureBoilerplate(FortressException e) {
   System.err.println(e.getMessage());
   e.printInterpreterStackTrace(System.err);
   if (Debug.stackTraceOn()) {
     e.printStackTrace();
   } else {
     System.err.println(turnOnDebugMessage);
   }
   (new Throwable()).printStackTrace();
 }
Exemple #3
0
  private static void walk(String fileName, List<String> args) throws UserError, Throwable {
    try {
      Iterable<? extends StaticError> errors = IterUtil.empty();
      try {
        eval(fileName, args, false);
      } catch (Throwable th) {
        // TODO FIXME what is the proper treatment of errors/exceptions etc.?
        if (th instanceof FortressException) {
          FortressException pe = (FortressException) th;
          if (pe.getStaticErrors() != null) errors = pe.getStaticErrors();
        }
        if (th instanceof RuntimeException) throw (RuntimeException) th;
        if (th instanceof Error) throw (Error) th;
        throw new WrappedException(th, Debug.stackTraceOn());
      }

      if (!IterUtil.isEmpty(errors)) {
        for (StaticError error : errors) {
          System.err.println(error);
        }
        System.exit(-1);
      }
      // If there are no errors,
      // all components will have been written to disk
      // by the CacheBasedRepository.
    } catch (StaticError e) {
      System.err.println(e);
      if (Debug.stackTraceOn()) {
        e.printStackTrace();
      }
      System.exit(-1);
    } catch (RepositoryError e) {
      throw e;
    } catch (LabelException e) {
      System.err.println(e.getMessage());
      if (Debug.stackTraceOn()) {
        e.printStackTrace();
      } else {
        System.err.println(turnOnDebugMessage);
      }
      System.exit(1);
    } catch (FortressException e) {
      failureBoilerplate(e);
      System.exit(1);
    }
  }