Skip to content
  • Gábor Szeder's avatar
    t9400-git-cvsserver-server: don't rely on the output of 'test_cmp' · 54ce2e9b
    Gábor Szeder authored and Junio C Hamano's avatar Junio C Hamano committed
    The test 'cvs update (-p)' redirects and checks 'test_cmp's stdout and
    even its stderr.  The commit introducing this test in 6e8937a0
    
    
    (cvsserver: Add test for update -p, 2008-03-27) doesn't discuss why,
    in fact its log message only consists of that subject line.  Anyway,
    weird as it is, it kind of made sense due to the way that test was
    structured:
    
    After a bit of preparation, this test updates four files via CVS and
    checks their contents using 'test_cmp', but it does so in a for loop
    iterating over the names of those four files.  Now, the exit status of
    a for loop is the exit status of the last command executed in the
    loop, meaning that the test can't simply rely on the exit code of
    'test_cmp' in the loop's body.  Instead, the test works it around by
    relying on the stdout of 'test_cmp' being silent on success and
    showing the diff on failure, as it appends the stdout of all four
    'test_cmp' invocations to a single file and checks that file's
    emptiness after the loop (with 'test -z "$(cat ...)"', no less; there
    was no 'test_must_be_empty' back then).  Furthermore, the test
    redirects the stderr of those 'test_cmp' invocations to this file,
    too: while 'test_cmp' itself doesn't output anything to stderr, the
    invoked 'diff' or 'cmp' commands do send their error messages there,
    e.g. if they can't open a file because its name was misspelled.
    
    This also makes this test fail when the test script is run with '-x'
    tracing (and using a shell other than a Bash version supporting
    BASH_XTRACEFD), because 'test_cmp's stderr contains the trace of the
    'diff' command executed inside the helper function, throwing off the
    subsequent emptiness check.
    
    Stop relying on 'test_cmp's output and instead run 'test_cmp a b ||
    return 1' in the for loop in order to make 'test_cmp's error code fail
    the test.  Furthermore, add the missing && after the cvs command to
    create a && chain in the loop's body.
    
    After this change t9400 passes with '-x', even when running with
    /bin/sh.
    
    Signed-off-by: default avatarSZEDER Gábor <szeder.dev@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    54ce2e9b