Exemple #1
0
static void tokenizer_test(const char *in, const char *expected, int split)
{
    char filename[1024];
    int fd;
    ssize_t len = strlen(expected);
    size_t inlen = strlen(in);

    if(split) {
        cli_js_process_buffer(state, in, inlen/2);
        cli_js_process_buffer(state, in + inlen/2, inlen - inlen/2);
    } else {
        cli_js_process_buffer(state, in, inlen);
    }

    cli_js_parse_done(state);
    cli_js_output(state, tmpdir);
    snprintf(filename, 1023, "%s/javascript", tmpdir);

    fd = open(filename, O_RDONLY);
    if(fd < 0) {
        jstest_teardown();
        fail_fmt("failed to open output file: %s", filename);
    }

    diff_file_mem(fd, expected, len);
}
Exemple #2
0
/*
** Output the differences between two check-ins.
*/
static void diff_all_two_versions(
  const char *zFrom,
  const char *zTo,
  const char *zDiffCmd,
  int ignoreEolWs
){
  Manifest mFrom, mTo;
  int iFrom, iTo;

  manifest_from_name(zFrom, &mFrom);
  manifest_from_name(zTo, &mTo);
  iFrom = iTo = 0;
  while( iFrom<mFrom.nFile && iTo<mTo.nFile ){
    int cmp;
    if( iFrom>=mFrom.nFile ){
      cmp = +1;
    }else if( iTo>=mTo.nFile ){
      cmp = -1;
    }else{
      cmp = strcmp(mFrom.aFile[iFrom].zName, mTo.aFile[iTo].zName);
    }
    if( cmp<0 ){
      printf("DELETED %s\n", mFrom.aFile[iFrom].zName);
      iFrom++;
    }else if( cmp>0 ){
      printf("ADDED   %s\n", mTo.aFile[iTo].zName);
      iTo++;
    }else if( strcmp(mFrom.aFile[iFrom].zUuid, mTo.aFile[iTo].zUuid)==0 ){
      /* No changes */
      iFrom++;
      iTo++;
    }else{
      Blob f1, f2;
      int rid;
      printf("CHANGED %s\n", mFrom.aFile[iFrom].zName);
      printf("Index: %s\n======================================="
             "============================\n",
             mFrom.aFile[iFrom].zName
      );
      rid = uuid_to_rid(mFrom.aFile[iFrom].zUuid, 0);
      content_get(rid, &f1);
      rid = uuid_to_rid(mTo.aFile[iTo].zUuid, 0);
      content_get(rid, &f2);
      diff_file_mem(&f1, &f2, mFrom.aFile[iFrom].zName, zDiffCmd, ignoreEolWs);
      blob_reset(&f1);
      blob_reset(&f2);
      iFrom++;
      iTo++;
    }
  }
  manifest_clear(&mFrom);
  manifest_clear(&mTo);
}
void diff_files(int fd, int ref_fd)
{
	char *ref;
	ssize_t nread;
	off_t siz = lseek(ref_fd, 0, SEEK_END);
	fail_unless_fmt(siz != -1, "lseek failed");

	ref = cli_malloc(siz);
	fail_unless_fmt(!!ref, "unable to malloc buffer: %d", siz);

	fail_unless_fmt(lseek(ref_fd, 0, SEEK_SET) == 0,"lseek failed");
	nread = read(ref_fd, ref, siz);
        fail_unless_fmt(nread == siz, "short read, expected: %ld, was: %ld", siz, nread);
	close(ref_fd);
	diff_file_mem(fd, ref, siz);
	free(ref);
}
Exemple #4
0
/*
** Output the differences between two versions of a single file.
** zFrom and zTo are the check-ins containing the two file versions.
** The filename is contained in g.argv[2].
*/
static void diff_one_two_versions(
  const char *zFrom,
  const char *zTo,
  const char *zDiffCmd,
  int ignoreEolWs
){
  char *zName;
  Blob fname;
  Blob v1, v2;
  file_tree_name(g.argv[2], &fname, 1);
  zName = blob_str(&fname);
  historical_version_of_file(zFrom, zName, &v1, 0);
  historical_version_of_file(zTo, zName, &v2, 0);
  diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
  blob_reset(&v1);
  blob_reset(&v2);
  blob_reset(&fname);
}