Skip to content
Branch: bleeding
Commits on Aug 23, 2019
  1. io: fix cr_file_match_file matching only the last block.

    Ethiraric authored and Snaipe committed May 2, 2019
    With each iteration of the loop, `match` was unconditionally reassigned
    to whatever the return of `!memcmp(buf1, buf2, read1)` was. This causes
    the result of comparing previous blocks to be overwritten without being
    This PR exits the loop early as soon as a difference is found.
    This case isn't trivial to test since it requires files larger than a
    block (512o) to be matched. I have tested it locally by manually setting
    the buffer sizes to 2 and with smaller files.
    I don't know how to add tests for it alongside existing tests in this
    project but would gladly do it if provided guidance.
Commits on Jan 31, 2018
  1. `cr_file_match_str` succeeds on empty file&string.

    Ethiraric committed Jan 31, 2018
    The following test would not run correctly:
    Test(putstr_second, test_outputs, .init = cr_redirect_stdout) {
    This is due to the `matches` variable being set to 0 by default. When
    the file is empty, the main loop is not run and `matches` never gets the
    chance to be updated. The function thus returned that the file and the
    string do not match.
    A unit tests has been added to prevent further regression.
    An `if` statement has also been added before the consuming loop in
    `cr_file_match_str` which avoids an unnecessary call to `fread` if we
    already know that the stream is empty.
Commits on Nov 22, 2017
  1. Make cr_file_match_str fail if str is longer.

    Ethiraric committed Nov 21, 2017
    When using cr_file_match_str, if the provided string we want to match
    the file against is longer than the contents of the file, the function
    returns that the file matches the string.
    This function is used by many other assertion routines (namely those
    asserting the contents of the standard output streams). This can be very
    error-prone when designing tests such as the following:
    Test(criterion, cr_file_match_str, .init = cr_redirect_stdout)
      printf("%s%d%s", "string", 42, "other");
    This commit makes it so that cr_file_match_str detects this kind of
    Note: It does not alter the fact that the function consumes all of the
    Fix unit tests. `std::cin >> s` reads only the first word from the
    stream, while we want the entire input line to be read.
You can’t perform that action at this time.