예제 #1
0
파일: testfiles.c 프로젝트: EmuxEvans/ion-c
/**
 * Walk the contents of the given path, executing fn over each real file for
 * which file_predicate returns true.
 * The path MAY end in slash if its a directory
 */
iERR visit_files(char             *parentpath
               , char             *filename
               , FILE_PREDICATE_FN file_predicate
               , LOOP_FN           fn
               , char             *fn_name
) {
    iENTER;
    DIR             *dir;
    BOOL             skip;
    char            *fullfilepath, *localfile;
    char             fullfilepathbuffer[MAX_TEMP_STRING];
    struct dirent   *d;

    fullfilepath = test_concat_filename(fullfilepathbuffer, MAX_TEMP_STRING, parentpath, filename);

    // Are we visiting a directory or a regular file?
    dir = DIR_OPEN(fullfilepath);
    if (dir) {
        IF_PRINT("STARTING %s over %s\n\n", fn_name, fullfilepath);

        while ((d = DIR_NEXT(dir)) != NULL)
        {
            localfile = d->d_name;

            // Ignore magic files in the directory listing.
            if (   strcmp(localfile, "." ) != 0
                && strcmp(localfile, "..") != 0)
            {
                IONDEBUG(visit_files(fullfilepath, localfile, file_predicate, fn, fn_name), "visit files");
            }
        }
        DIR_CLOSE(dir);

        IF_PRINT("\nFINISHED %s over %s\n\n", fn_name, localfile);
    }
    else {
        skip = is_always_skipped(fullfilepath);
        if (!skip && file_predicate) {
            skip = ((*file_predicate)(filename)) != TRUE;
        }
        if (!skip) {

            IONDEBUG(test_one_file(fullfilepath, fn, fn_name), "test one file");

        }
        else {
            // Skipping the file
            IF_PRINT("*** SKIPPING %s\n", fullfilepath);
        }
    }

    iRETURN;
}
예제 #2
0
int main(int argc, char* argv[])
{
  if (argc < 2) {
    std::cerr << "Missing input file" << std::endl;
    return -1;
  }

  // TBD: Replace with better parsing!
  int i = 1;
  int verbose_level = 0;
  if (argc > 2) {
    if ((argc > 3) && (std::strncmp(argv[1], "-v", 2) == 0)) {
      verbose_level = atoi(argv[2]);
      i += 2;
    }
  }

  int success = 0;
  for (; i < argc; ++i) {
    std::string str(argv[i]);
    if (str.empty()) continue;

    std::string::iterator itr = str.end();
    --itr;
    while (itr != str.begin()) {
      std::string::iterator tmp = itr;
      --tmp;
      if (*itr == 't')  break;

      str.erase(itr);
      itr = tmp;
    }
    if (str.size() <= 1) continue;
    std::ifstream inp(str.c_str());
    if (!inp.is_open()) {
      std::cerr << "Failed to open " << str << std::endl;
      return -1;
    }
    if (! test_one_file(inp, verbose_level)) {
      inp.close();
      std::cerr << str << ": ERROR" << std::endl;
      success = -1;
    }
    else std::cout <<str << ": succeeded" << std::endl;
    inp.close();
  }

  return success;
}