1. 21 10月, 2020 1 次提交
  2. 10 8月, 2020 1 次提交
    • E
      test_cmp: diagnose incorrect arguments · d572f52a
      Eric Sunshine 提交于
      Under normal circumstances, if a test author misspells a filename passed
      to test_cmp(), the error is quickly discovered when the test fails
      unexpectedly due to test_cmp() being unable to find the file. However,
      if the test is expected to fail, as with test_expect_failure(), a
      misspelled filename as argument to test_cmp() will go unnoticed since
      the test will indeed fail, but for the wrong reason. Make it easier for
      test authors to discover such problems early by sanity-checking the
      arguments to test_cmp(). To avoid penalizing all clients of test_cmp()
      in the general case, only check for missing files if the comparison
      fails.
      
      While at it, make test_cmp_bin() sanity-check its arguments, as well.
      Signed-off-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d572f52a
  3. 12 4月, 2020 3 次提交
  4. 29 3月, 2020 1 次提交
    • J
      test-lib-functions: simplify packetize() stdin code · cacae432
      Jeff King 提交于
      The code path in packetize() for reading stdin needs to handle NUL
      bytes, so we can't rely on shell variables. However, the current code
      takes a whopping 4 processes and uses a temporary file. We can do this
      much more simply and efficiently by using a single perl invocation (and
      we already rely on perl in the matching depacketize() function).
      
      We'll keep the non-stdin code path as it is, since that uses zero extra
      processes.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      cacae432
  5. 28 3月, 2020 1 次提交
    • J
      test-lib-functions: make packetize() more efficient · 88124ab2
      Jeff King 提交于
      The packetize() function takes its input on stdin, and requires 4
      separate sub-processes to format a simple string. We can do much better
      by getting the length via the shell's "${#packet}" construct. The one
      caveat is that the shell can't put a NUL into a variable, so we'll have
      to continue to provide the stdin form for a few calls.
      
      There are a few other cleanups here in the touched code:
      
       - the stdin form of packetize() had an extra stray "%s" when printing
         the packet
      
       - the converted calls in t5562 can be made simpler by redirecting
         output as a block, rather than repeated appending
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      88124ab2
  6. 25 3月, 2020 1 次提交
  7. 15 2月, 2020 1 次提交
    • J
      t5310: factor out bitmap traversal comparison · ea047a8e
      Jeff King 提交于
      We check the results of "rev-list --use-bitmap-index" by comparing it to
      the same traversal without the bitmap option. However, this is a little
      tricky to do because of some output differences (see the included
      comment for details). Let's pull this out into a helper function, since
      we'll be adding some similar tests.
      
      While we're at it, let's also try to confirm that the bitmap output did
      indeed use bitmaps. Since the code internally falls back to the
      non-bitmap path in some cases, the tests are at risk of becoming trivial
      noops.
      
      This is a bit fragile, as not all outputs will differ (e.g., looking at
      only the commits from a fully-bitmapped pack will end up exactly the
      same as the normal traversal order, since it also matches the pack
      order). So we'll provide an escape hatch by which tests can disable this
      check (which should only be used after manually confirming that bitmaps
      kicked in).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ea047a8e
  8. 27 11月, 2019 1 次提交
  9. 23 11月, 2019 1 次提交
    • S
      tests: add 'test_bool_env' to catch non-bool GIT_TEST_* values · 43a2afee
      SZEDER Gábor 提交于
      Since 3b072c57 (tests: replace test_tristate with "git env--helper",
      2019-06-21) we get the normalized bool values of various GIT_TEST_*
      environment variables via 'git env--helper'.  Now, while the 'git
      env--helper' command itself does catch invalid values in the
      environment variable or in the given --default and exits with error
      (exit code 128 or 129, respectively), it's invoked in conditions like
      'if ! git env--helper ...', which means that all invalid bool values
      are interpreted the same as the ordinary 'false' (exit code 1).  This
      has led to inadvertently skipped httpd tests in our CI builds for a
      couple of weeks, see 39602906 (ci: restore running httpd tests,
      2019-09-06).
      
      Let's be more careful about what the test suite accepts as bool values
      in GIT_TEST_* environment variables, and error out loud and clear on
      invalid values instead of simply skipping tests.  Add the
      'test_bool_env' helper function to encapsulate the invocation of 'git
      env--helper' and the verification of its exit code, and replace all
      invocations of that command in our test framework and test suite with
      a call to this new helper (except in 't0017-env-helper.sh', of
      course).
      
        $ GIT_TEST_GIT_DAEMON=YesPlease ./t5570-git-daemon.sh
        fatal: bad numeric config value 'YesPlease' for 'GIT_TEST_GIT_DAEMON': invalid unit
        error: test_bool_env requires bool values both for $GIT_TEST_GIT_DAEMON and for the default fallback
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      43a2afee
  10. 21 11月, 2019 1 次提交
    • D
      t: teach test_cmp_rev to accept ! for not-equals · 2c9e125b
      Denton Liu 提交于
      In the case where we are using test_cmp_rev() to report not-equals, we
      write `! test_cmp_rev`. However, since test_cmp_rev() contains
      
      	r1=$(git rev-parse --verify "$1") &&
      	r2=$(git rev-parse --verify "$2") &&
      
      `! test_cmp_rev` will succeed if any of the rev-parses fail. This
      behavior is not desired. We want the rev-parses to _always_ be
      successful.
      
      Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
      do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
      in all tests to take advantage of this new functionality.
      
      Also, rewrite the rev-parse logic to end with a `|| return 1` instead of
      &&-chaining into the rev-comparison logic. This makes it obvious to
      future readers that we explicitly intend on returning early if either of
      the rev-parses fail.
      Signed-off-by: NDenton Liu <liu.denton@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2c9e125b
  11. 04 10月, 2019 1 次提交
  12. 09 8月, 2019 1 次提交
    • J
      t: decrease nesting in test_oid_to_path · 1c1f6e03
      Jonathan Nieder 提交于
      t1410.3 ("corrupt and checks") fails when run using dash versions
      before 0.5.8, with a cryptic message:
      
      	mv: cannot stat '.git/objects//e84adb2704cbd49549e52169b4043871e13432': No such file or directory
      
      The function generating that path:
      
      	test_oid_to_path () {
      		echo "${1%${1#??}}/${1#??}"
      	}
      
      which is supposed to produce a result like
      
      	12/3456789....
      
      But a dash bug[*] causes it to instead expand to
      
      	/3456789...
      
      The stream of symbols that makes up this function is hard for humans
      to follow, too.  The complexity mostly comes from the repeated use of
      the expression ${1#??} for the basename of the loose object.  Use a
      variable instead --- nowadays, the dialect of shell used by Git
      permits local variables, so this is cheap.
      
      An alternative way to work around [*] is to remove the double-quotes
      around test_oid_to_path's return value.  That makes the expression
      easier for dash to read, but harder for humans.  Let's prefer the
      rephrasing that's helpful for humans, too.
      
      Noticed by building on Ubuntu trusty, which uses dash 0.5.7.
      
      [*] Fixed by v0.5.8~13 ("[EXPAND] Propagate EXP_QPAT in subevalvar, 2013-08-23).
      Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1c1f6e03
  13. 06 8月, 2019 1 次提交
    • S
      tests: show the test name and number at the start of verbose output · ffe1afe6
      SZEDER Gábor 提交于
      The verbose output of every test looks something like this:
      
        expecting success:
                echo content >file &&
                git add file &&
                git commit -m "add file"
      
        [master (root-commit) d1fbfbd] add file
         Author: A U Thor <author@example.com>
         1 file changed, 1 insertion(+)
         create mode 100644 file
        ok 1 - commit works
      
      i.e. first an "expecting success" (or "checking known breakage") line
      followed by the commands to be executed, then the output of those
      comamnds, and finally an "ok"/"not ok" line containing the test name.
      Note that the test's name is only shown at the very end.
      
      With '-x' tracing enabled and/or in longer tests the verbose output
      might be several screenfulls long, making it harder than necessary to
      find where the output of the test with a given name starts (especially
      when the outputs to different file descriptors are racing, and the
      "expecting success"/command block arrives earlier than the "ok" line
      of the previous test).
      
      Print the test name at the start of the test's verbose output, i.e. at
      the end of the "expecting success" and "checking known breakage"
      lines, to make the start of a particular test a bit easier to
      recognize.  Also print the test script and test case numbers, to help
      those poor souls who regularly have to scan through the combined
      verbose output of several test scripts.
      
      So the dummy test above would start like this:
      
        expecting success of 9999.1 'commit works':
                echo content >file &&
        [...]
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ffe1afe6
  14. 03 7月, 2019 1 次提交
    • J
      test-lib: introduce test_commit_bulk · b1c36cb8
      Jeff King 提交于
      Some tests need to create a string of commits. Doing this with
      test_commit is very heavy-weight, as it needs at least one process per
      commit (and in fact, uses several).
      
      For bulk creation, we can do much better by using fast-import, but it's
      often a pain to generate the input. Let's provide a helper to do so.
      
      We'll use t5310 as a guinea pig, as it has three 10-commit loops. Here
      are hyperfine results before and after:
      
        [before]
        Benchmark #1: ./t5310-pack-bitmaps.sh --root=/var/ram/git-tests
          Time (mean ± σ):      2.846 s ±  0.305 s    [User: 3.042 s, System: 0.919 s]
          Range (min … max):    2.250 s …  3.210 s    10 runs
      
        [after]
        Benchmark #1: ./t5310-pack-bitmaps.sh --root=/var/ram/git-tests
          Time (mean ± σ):      2.210 s ±  0.174 s    [User: 2.570 s, System: 0.604 s]
          Range (min … max):    1.999 s …  2.590 s    10 runs
      
      So we're over 20% faster, while making the callers slightly shorter. We
      added a lot more lines in test-lib-function.sh, of course, and the
      helper is way more featureful than we need here. But my hope is that it
      will be flexible enough to use in more places.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b1c36cb8
  15. 02 7月, 2019 1 次提交
  16. 25 6月, 2019 1 次提交
    • J
      t0001: fix on case-insensitive filesystems · ed33bd8f
      Johannes Schindelin 提交于
      On a case-insensitive filesystem, such as HFS+ or NTFS, it is possible
      that the idea Bash has of the current directory differs in case from
      what Git thinks it is. That's totally okay, though, and we should not
      expect otherwise.
      
      On Windows, for example, when you call
      
      	cd C:\GIT-SDK-64
      
      in a PowerShell and there exists a directory called `C:\git-sdk-64`, the
      current directory will be reported in all upper-case. Even in a Bash
      that you might call from that PowerShell. Git, however, will have
      normalized this via `GetFinalPathByHandle()`, and the expectation in
      t0001 that the recorded gitdir will match what `pwd` says will be
      violated.
      
      Let's address this by comparing these paths in a case-insensitive
      manner when `core.ignoreCase` is `true`.
      
      Reported by Jameson Miller.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      ed33bd8f
  17. 22 6月, 2019 2 次提交
    • Æ
      tests: make GIT_TEST_FAIL_PREREQS a boolean · c7400399
      Ævar Arnfjörð Bjarmason 提交于
      Change the GIT_TEST_FAIL_PREREQS variable from being "non-empty?" to
      being a more standard boolean variable. I recently added the variable
      in dfe1a17d ("tests: add a special setup where prerequisites fail",
      2019-05-13), having to add another "non-empty?" special-case is what
      prompted me to write the "git env--helper" utility being used here.
      
      Converting this one is a bit tricky since we use it so early and
      frequently in the guts of the test code itself, so let's set a
      GIT_TEST_FAIL_PREREQS_INTERNAL which can be tested with the old "test
      -n" for the purposes of the shell code, and change the user-exposed
      and documented GIT_TEST_FAIL_PREREQS variable to a boolean.
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c7400399
    • Æ
      tests: replace test_tristate with "git env--helper" · 3b072c57
      Ævar Arnfjörð Bjarmason 提交于
      The test_tristate helper introduced in 83d842dc ("tests: turn on
      network daemon tests by default", 2014-02-10) can now be better
      implemented with "git env--helper" to give the variables in question
      the standard boolean behavior.
      
      The reason for the "tristate" was to have all of false/true/auto,
      where "auto" meant either "false" or "true" depending on what the
      fallback was. With the --default option to "git env--helper" we can
      simply have e.g. GIT_TEST_HTTPD where we know if it's true because the
      user asked explicitly ("true"), or true implicitly ("auto").
      
      This breaks backwards compatibility for explicitly setting "auto" for
      these variables, but I don't think anyone cares. That was always
      intended to be internal.
      
      This means the test_normalize_bool() code in test-lib-functions.sh
      goes away in addition to test_tristate(). We still need the
      test_skip_or_die() helper, but now it takes the variable name instead
      of the value, and uses "git env--bool" to distinguish a default "true"
      from an explicit "true" (in those "explicit true" cases we want to
      fail the test in question).
      Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3b072c57
  18. 14 5月, 2019 1 次提交
  19. 05 4月, 2019 1 次提交
    • T
      t: move 'hex2oct' into test-lib-functions.sh · 5c07647d
      Taylor Blau 提交于
      The helper 'hex2oct' is used to convert base-16 encoded data into a
      base-8 binary form, and is useful for preparing data for commands that
      accept input in a binary format, such as 'git hash-object', via
      'printf'.
      
      This helper is defined identically in three separate places throughout
      't'. Move the definition to test-lib-function.sh, so that it can be used
      in new test suites, and its definition is not redundant.
      
      This will likewise make our job easier in the subsequent commit, which
      also uses 'hex2oct'.
      Signed-off-by: NTaylor Blau <me@ttaylorr.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5c07647d
  20. 14 3月, 2019 1 次提交
    • J
      test-lib: introduce 'test_atexit' · 900721e1
      Johannes Schindelin 提交于
      When running Apache, 'git daemon', or p4d, we want to kill them at the
      end of the test script, otherwise a leftover daemon process will keep
      its port open indefinitely, and thus will interfere with subsequent
      executions of the same test script.
      
      So far, we stop these daemon processes "manually", i.e.:
      
        - by registering functions or commands in the trap on EXIT to stop
          the daemon while preserving the last seen exit code before the
          trap (to deal with a failure when run with '--immediate' or with
          interrupts by ctrl-C),
      
        - and by invoking these functions/commands last thing before
          'test_done' (and sometimes restoring the test framework's default
          trap on EXIT, to prevent the daemons from being killed twice).
      
      On one hand, we do this inconsistently, e.g. 'git p4' tests invoke
      different functions in the trap on EXIT and in the last test before
      'test_done', and they neither restore the test framework's default trap
      on EXIT nor preserve the last seen exit code.  On the other hand, this
      is error prone, because, as shown in a previous patch in this series,
      any output from the cleanup commands in the trap on EXIT can prevent a
      proper cleanup when a test script run with '--verbose-log' and certain
      shells, notably 'dash', is interrupted.
      
      Let's introduce 'test_atexit', which is loosely modeled after
      'test_when_finished', but has a broader scope: rather than running the
      commands after the current test case, run them when the test script
      finishes, and also run them when the test is interrupted, or exits
      early in case of a failure while the '--immediate' option is in
      effect.
      
      When running the cleanup commands at the end of a successful test,
      then they will be run in 'test_done' before it removes the trash
      directory, i.e. the cleanup commands will still be able to access any
      pidfiles or socket files in there.  When running the cleanup commands
      after an interrupt or failure with '--immediate', then they will be
      run in the trap on EXIT.  In both cases they will be run in
      'test_eval_', i.e. both standard error and output of all cleanup
      commands will go where they should according to the '-v' or
      '--verbose-log' options, and thus won't cause any troubles when
      interrupting a test script run with '--verbose-log'.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      900721e1
  21. 08 3月, 2019 1 次提交
  22. 20 2月, 2019 1 次提交
    • J
      tests: teach the test-tool to generate NUL bytes and use it · d5cfd142
      Johannes Schindelin 提交于
      In cc95bc20 (t5562: replace /dev/zero with a pipe from
      generate_zero_bytes, 2019-02-09), we replaced usage of /dev/zero (which
      is not available on NonStop, apparently) by a Perl script snippet to
      generate NUL bytes.
      
      Sadly, it does not seem to work on NonStop, as t5562 reportedly hangs.
      
      Worse, this also hangs in the Ubuntu 16.04 agents of the CI builds on
      Azure Pipelines: for some reason, the Perl script snippet that is run
      via `generate_zero_bytes` in t5562's 'CONTENT_LENGTH overflow ssite_t'
      test case tries to write out an infinite amount of NUL bytes unless a
      broken pipe is encountered, that snippet never encounters the broken
      pipe, and keeps going until the build times out.
      
      Oddly enough, this does not reproduce on the Windows and macOS agents,
      nor in a local Ubuntu 18.04.
      
      This developer tried for a day to figure out the exact circumstances
      under which this hang happens, to no avail, the details remain a
      mystery.
      
      In the end, though, what counts is that this here change incidentally
      fixes that hang (maybe also on NonStop?). Even more positively, it gets
      rid of yet another unnecessary Perl invocation.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d5cfd142
  23. 13 2月, 2019 1 次提交
  24. 12 2月, 2019 1 次提交
    • S
      test-lib: fix non-portable pattern bracket expressions · 7d661e5e
      SZEDER Gábor 提交于
      Use a '!' character to start a non-matching pattern bracket
      expression, as specified by POSIX in Shell Command Language section
      2.13.1 Patterns Matching a Single Character [1].
      
      I used '^' instead in three places in the previous three commits, to
      verify that the arguments of the '--stress=' and '--stress-limit='
      options and the values of various '*_PORT' environment variables are
      valid numbers.  With certain shells, at least with dash (upstream and
      in Ubuntu 14.04) and mksh, this led to various undesired behaviors:
      
        # error message in case of a valid number
        $ ~/src/dash/src/dash ./t3903-stash.sh --stress=8
        error: --stress=<N> requires the number of jobs to run
      
        # not the expected error message
        $ ~/src/dash/src/dash ./t3903-stash.sh --stress=foo
        ./t3903-stash.sh: 238: test: Illegal number: foo
      
        # no error message at all?!
        $ mksh ./t3903-stash.sh --stress=foo
        $ echo $?
        0
      
      Some other shells, e.g. Bash (even in posix mode), ksh, dash in Ubuntu
      16.04 or later, are apparently happy to accept '^' just as well.
      
      [1] http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_13Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7d661e5e
  25. 08 1月, 2019 2 次提交
    • S
      test-lib: add the '--stress' option to run a test repeatedly under load · fb7d1e3a
      SZEDER Gábor 提交于
      Unfortunately, we have a few flaky tests, whose failures tend to be
      hard to reproduce.  We've found that the best we can do to reproduce
      such a failure is to run the test script repeatedly while the machine
      is under load, and wait in the hope that the load creates enough
      variance in the timing of the test's commands that a failure is
      evenually triggered.  I have a command to do that, and I noticed that
      two other contributors have rolled their own scripts to do the same,
      all choosing slightly different approaches.
      
      To help reproduce failures in flaky tests, introduce the '--stress'
      option to run a test script repeatedly in multiple parallel jobs until
      one of them fails, thereby using the test script itself to increase
      the load on the machine.
      
      The number of parallel jobs is determined by, in order of precedence:
      the number specified as '--stress=<N>', or the value of the
      GIT_TEST_STRESS_LOAD environment variable, or twice the number of
      available processors (as reported by the 'getconf' utility), or 8.
      
      Make '--stress' imply '--verbose -x --immediate' to get the most
      information about rare failures; there is really no point in spending
      all the extra effort to reproduce such a failure, and then not know
      which command failed and why.
      
      To prevent the several parallel invocations of the same test from
      interfering with each other:
      
        - Include the parallel job's number in the name of the trash
          directory and the various output files under 't/test-results/' as
          a '.stress-<Nr>' suffix.
      
        - Add the parallel job's number to the port number specified by the
          user or to the test number, so even tests involving daemons
          listening on a TCP socket can be stressed.
      
        - Redirect each parallel test run's verbose output to
          't/test-results/$TEST_NAME.stress-<nr>.out', because dumping the
          output of several parallel running tests to the terminal would
          create a big ugly mess.
      
      For convenience, print the output of the failed test job at the end,
      and rename its trash directory to end with the '.stress-failed'
      suffix, so it's easy to find in a predictable path (OTOH, all absolute
      paths recorded in the trash directory become invalid; we'll see
      whether this causes any issues in practice).  If, in an unlikely case,
      more than one jobs were to fail nearly at the same time, then print
      the output of all failed jobs, and rename the trash directory of only
      the last one (i.e. with the highest job number), as it is the trash
      directory of the test whose output will be at the bottom of the user's
      terminal.
      
      Based on Jeff King's 'stress' script.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fb7d1e3a
    • S
      test-lib-functions: introduce the 'test_set_port' helper function · fa840581
      SZEDER Gábor 提交于
      Several test scripts run daemons like 'git-daemon' or Apache, and
      communicate with them through TCP sockets.  To have unique ports where
      these daemons are accessible, the ports are usually the number of the
      corresponding test scripts, unless the user overrides them via
      environment variables, and thus all those tests and test libs contain
      more or less the same bit of one-liner boilerplate code to find out
      the port.  The last patch in this series will make this a bit more
      complicated.
      
      Factor out finding the port for a daemon into the common helper
      function 'test_set_port' to avoid repeating ourselves.
      
      Take special care of test scripts with "low" numbers:
      
        - Test numbers below 1024 would result in a port that's only usable
          as root, so set their port to '10000 + test-nr' to make sure it
          doesn't interfere with other tests in the test suite.  This makes
          the hardcoded port number in 't0410-partial-clone.sh' unnecessary,
          remove it.
      
        - The shell's arithmetic evaluation interprets numbers with leading
          zeros as octal values, which means that test number below 1000 and
          containing the digits 8 or 9 will trigger an error.  Remove all
          leading zeros from the test numbers to prevent this.
      
      Note that the 'git p4' tests are unlike the other tests involving
      daemons in that:
      
        - 'lib-git-p4.sh' doesn't use the test's number for unique port as
          is, but does a bit of additional arithmetic on top [1].
      
        - The port is not overridable via an environment variable.
      
      With this patch even 'git p4' tests will use the test's number as
      default port, and it will be overridable via the P4DPORT environment
      variable.
      
      [1] Commit fc002330 (git-p4 tests: refactor and cleanup, 2011-08-22)
          introduced that "unusual" unique port computation without
          explaining why it was necessary (as opposed to simply using the
          test number as is).  It seems to be just unnecessary complication,
          and in any case that commit came way before the "test nr as unique
          port" got "standardized" for other daemons in commits c44132fc
          (tests: auto-set git-daemon port, 2014-02-10), 3bb486e4 (tests:
          auto-set LIB_HTTPD_PORT from test name, 2014-02-10), and
          bf9d7df9 (t/lib-git-svn.sh: improve svnserve tests with parallel
          make test, 2017-12-01).
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fa840581
  26. 20 11月, 2018 2 次提交
    • S
      test-lib-functions: make 'test_cmp_rev' more informative on failure · 30d0b6dc
      SZEDER Gábor 提交于
      The 'test_cmp_rev' helper is merely a wrapper around 'test_cmp'
      checking the output of two 'git rev-parse' commands, which means that
      its output on failure is not particularly informative, as it's
      basically two OIDs with a bit of extra clutter of the diff header, but
      without any indication of which two revisions have caused the failure:
      
        --- expect.rev  2018-11-17 14:02:11.569747033 +0000
        +++ actual.rev  2018-11-17 14:02:11.569747033 +0000
        @@ -1 +1 @@
        -d79ce1670bdcb76e6d1da2ae095e890ccb326ae9
        +139b20d8e6c5b496de61f033f642d0e3dbff528d
      
      It also pollutes the test repo with these two intermediate files,
      though that doesn't seem to cause any complications in our current
      tests (meaning that I couldn't find any tests that have to work around
      the presence of these files by explicitly removing or ignoring them).
      
      Enhance 'test_cmp_rev' to provide a more useful output on failure with
      less clutter:
      
        error: two revisions point to different objects:
          'HEAD^': d79ce1670bdcb76e6d1da2ae095e890ccb326ae9
          'extra': 139b20d8e6c5b496de61f033f642d0e3dbff528d
      
      Doing so is more convenient when storing the OIDs outputted by 'git
      rev-parse' in a local variable each, which, as a bonus, won't pollute
      the repository with intermediate files.
      
      While at it, also ensure that 'test_cmp_rev' is invoked with the right
      number of parameters, namely two.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      30d0b6dc
    • S
      tests: send "bug in the test script" errors to the script's stderr · 165293af
      SZEDER Gábor 提交于
      Some of the functions in our test library check that they were invoked
      properly with conditions like this:
      
        test "$#" = 2 ||
        error "bug in the test script: not 2 parameters to test-expect-success"
      
      If this particular condition is triggered, then 'error' will abort the
      whole test script with a bold red error message [1] right away.
      
      However, under certain circumstances the test script will be aborted
      completely silently, namely if:
      
        - a similar condition in a test helper function like
          'test_line_count' is triggered,
        - which is invoked from the test script's "main" shell [2],
        - and the test script is run manually (i.e. './t1234-foo.sh' as
          opposed to 'make t1234-foo.sh' or 'make test') [3]
        - and without the '--verbose' option,
      
      because the error message is printed from within 'test_eval_', where
      standard output is redirected either to /dev/null or to a log file.
      The only indication that something is wrong is that not all tests in
      the script are executed and at the end of the test script's output
      there is no "# passed all N tests" message, which are subtle and can
      easily go unnoticed, as I had to experience myself.
      
      Send these "bug in the test script" error messages directly to the
      test scripts standard error and thus to the terminal, so those bugs
      will be much harder to overlook.  Instead of updating all ~20 such
      'error' calls with a redirection, let's add a BUG() function to
      'test-lib.sh', wrapping an 'error' call with the proper redirection
      and also including the common prefix of those error messages, and
      convert all those call sites [4] to use this new BUG() function
      instead.
      
      [1] That particular error message from 'test_expect_success' is
          printed in color only when running with or without '--verbose';
          with '--tee' or '--verbose-log' the error is printed without
          color, but it is printed to the terminal nonetheless.
      
      [2] If such a condition is triggered in a subshell of a test, then
          'error' won't be able to abort the whole test script, but only the
          subshell, which in turn causes the test to fail in the usual way,
          indicating loudly and clearly that something is wrong.
      
      [3] Well, 'error' aborts the test script the same way when run
          manually or by 'make' or 'prove', but both 'make' and 'prove' pay
          attention to the test script's exit status, and even a silently
          aborted test script would then trigger those tools' usual
          noticable error messages.
      
      [4] Strictly speaking, not all those 'error' calls need that
          redirection to send their output to the terminal, see e.g.
          'test_expect_success' in the opening example, but I think it's
          better to be consistent.
      Signed-off-by: NSZEDER Gábor <szeder.dev@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      165293af
  27. 16 11月, 2018 1 次提交
    • J
      tests: explicitly use `git.exe` on Windows · 8abfdf44
      Johannes Schindelin 提交于
      On Windows, when we refer to `/an/absolute/path/to/git`, it magically
      resolves `git.exe` at that location. Except if something of the name
      `git` exists next to that `git.exe`. So if we call `$BUILD_DIR/git`, it
      will find `$BUILD_DIR/git.exe` *only* if there is not, say, a directory
      called `$BUILD_DIR/git`.
      
      Such a directory, however, exists in Git for Windows when building with
      Visual Studio (our Visual Studio project generator defaults to putting
      the build files into a directory whose name is the base name of the
      corresponding `.exe`).
      
      In the bin-wrappers/* scripts, we already take pains to use `git.exe`
      rather than `git`, as this could pick up the wrong thing on Windows
      (i.e. if there exists a `git` file or directory in the build directory).
      
      Now we do the same in the tests' start-up code.
      
      This also helps when testing an installed Git, as there might be even
      more likely some stray file or directory in the way.
      
      Note: the only way we can record whether the `.exe` suffix is by writing
      it to the `GIT-BUILD-OPTIONS` file and sourcing it at the beginning of
      `t/test-lib.sh`. This is not a requirement introduced by this patch, but
      we move the call to be able to use the `$X` variable that holds the file
      extension, if any.
      
      Note also: the many, many calls to `git this` and `git that` are
      unaffected, as the regular PATH search will find the `.exe` files on
      Windows (and not be confused by a directory of the name `git` that is
      in one of the directories listed in the `PATH` variable), while
      `/path/to/git` would not, per se, know that it is looking for an
      executable and happily prefer such a directory.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      8abfdf44
  28. 14 11月, 2018 1 次提交
  29. 09 11月, 2018 1 次提交
    • Æ
      i18n: make GETTEXT_POISON a runtime option · 6cdccfce
      Ævar Arnfjörð Bjarmason 提交于
      Change the GETTEXT_POISON compile-time + runtime GIT_GETTEXT_POISON
      test parameter to only be a GIT_TEST_GETTEXT_POISON=<non-empty?>
      runtime parameter, to be consistent with other parameters documented
      in "Running tests with special setups" in t/README.
      
      When I added GETTEXT_POISON in bb946bba ("i18n: add GETTEXT_POISON
      to simulate unfriendly translator", 2011-02-22) I was concerned with
      ensuring that the _() function would get constant folded if NO_GETTEXT
      was defined, and likewise that GETTEXT_POISON would be compiled out
      unless it was defined.
      
      But as the benchmark in my [1] shows doing a one-off runtime
      getenv("GIT_TEST_[...]") is trivial, and since GETTEXT_POISON was
      originally added the GIT_TEST_* env variables have become the common
      idiom for turning on special test setups.
      
      So change GETTEXT_POISON to work the same way. Now the
      GETTEXT_POISON=YesPlease compile-time option is gone, and running the
      tests with GIT_TEST_GETTEXT_POISON=[YesPlease|] can be toggled on/off
      without recompiling.
      
      This allows for conditionally amending tests to test with/without
      poison, similar to what 859fdc0c ("commit-graph: define
      GIT_TEST_COMMIT_GRAPH", 2018-08-29) did for GIT_TEST_COMMIT_GRAPH. Do
      some of that, now we e.g. always run the t0205-gettext-poison.sh test.
      
      I did enough there to remove the GETTEXT_POISON prerequisite, but its
      inverse C_LOCALE_OUTPUT is still around, and surely some tests using
      it can be converted to e.g. always set GIT_TEST_GETTEXT_POISON=.
      
      Notes on the implementation:
      
       * We still compile a dedicated GETTEXT_POISON build in Travis
         CI. Perhaps this should be revisited and integrated into the
         "linux-gcc" build, see ae59a4e4 ("travis: run tests with
         GIT_TEST_SPLIT_INDEX", 2018-01-07) for prior art in that area. Then
         again maybe not, see [2].
      
       * We now skip a test in t0000-basic.sh under
         GIT_TEST_GETTEXT_POISON=YesPlease that wasn't skipped before. This
         test relies on C locale output, but due to an edge case in how the
         previous implementation of GETTEXT_POISON worked (reading it from
         GIT-BUILD-OPTIONS) wasn't enabling poison correctly. Now it does,
         and needs to be skipped.
      
       * The getenv() function is not reentrant, so out of paranoia about
         code of the form:
      
             printf(_("%s"), getenv("some-env"));
      
         call use_gettext_poison() in our early setup in git_setup_gettext()
         so we populate the "poison_requested" variable in a codepath that's
         won't suffer from that race condition.
      
       * We error out in the Makefile if you're still saying
         GETTEXT_POISON=YesPlease to prompt users to change their
         invocation.
      
       * We should not print out poisoned messages during the test
         initialization itself to keep it more readable, so the test library
         hides the variable if set in $GIT_TEST_GETTEXT_POISON_ORIG during
         setup. See [3].
      
      See also [4] for more on the motivation behind this patch, and the
      history of the GETTEXT_POISON facility.
      
      1. https://public-inbox.org/git/871s8gd32p.fsf@evledraar.gmail.com/
      2. https://public-inbox.org/git/20181102163725.GY30222@szeder.dev/
      3. https://public-inbox.org/git/20181022202241.18629-2-szeder.dev@gmail.com/
      4. https://public-inbox.org/git/878t2pd6yu.fsf@evledraar.gmail.com/Signed-off-by: NÆvar Arnfjörð Bjarmason <avarab@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      6cdccfce
  30. 22 10月, 2018 1 次提交
  31. 14 9月, 2018 1 次提交
    • B
      t: add test functions to translate hash-related values · 2c02b110
      brian m. carlson 提交于
      Add several test functions to make working with various hash-related
      values easier.
      
      Add test_oid_init, which loads common hash-related constants and
      placeholder object IDs from the newly added files in t/oid-info.
      Provide values for these constants for both SHA-1 and SHA-256.
      
      Add test_oid_cache, which accepts data on standard input in the form of
      hash-specific key-value pairs that can be looked up later, using the
      same format as the files in t/oid-info.  Document this format in a
      t/oid-info/README directory so that it's easier to use in the future.
      
      Add test_oid, which is used to specify look up a per-hash value
      (produced on standard output) based on the key specified as its
      argument.  Usually the data to be looked up will be a hash-related
      constant (such as the size of the hash in binary or hexadecimal), a
      well-known or placeholder object ID (such as the all-zeros object ID or
      one consisting of "deadbeef" repeated), or something similar.  For these
      reasons, test_oid will usually be used within a command substitution.
      Consequently, redirect the error output to standard error, since
      otherwise it will not be displayed.
      
      Add test_detect_hash, which currently only detects SHA-1, and
      test_set_hash, which can be used to set a different hash algorithm for
      test purposes.  In the future, test_detect_hash will learn to actually
      detect the hash depending on how the testsuite is to be run.
      
      Use the local keyword within these functions to avoid overwriting other
      shell variables.  We have had a test balloon in place for a couple of
      releases to catch shells that don't have this keyword and have not
      received any reports of failure.  Note that the varying usages of local
      used here are supported by all common open-source shells supporting the
      local keyword.
      
      Test these new functions as part of t0000, which also serves to
      demonstrate basic usage of them.  In addition, add documentation on how
      to format the lookup data and how to use the test functions.
      
      Implement two basic lookup charts, one for common invalid or synthesized
      object IDs, and one for various facts about the hash function in use.
      Provide versions of the data for both SHA-1 and SHA-256.
      
      Since we use shell variables for storage, names used for lookup can
      currently consist only of shell identifier characters.  If this is a
      problem in the future, we can hash the names before use.
      Improved-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: Nbrian m. carlson <sandals@crustytoothpaste.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2c02b110
  32. 15 8月, 2018 1 次提交
  33. 09 8月, 2018 1 次提交
    • E
      t7406: prefer test_* helper functions to test -[feds] · 7e9055bb
      Elijah Newren 提交于
      test -e, test -s, etc. do not provide nice error messages when we hit
      test failures, so use the test_* helper functions from
      test-lib-functions.sh.
      
      Also, add test_path_exists() to test-lib-function.sh while at it, so
      that we don't need to worry whether submodule/.git is a file or a
      directory.  It currently is a file with contents of the form
         gitdir: ../.git/modules/submodule
      but it could be changed in the future to be a directory; this test
      only really cares that it exists.
      Signed-off-by: NElijah Newren <newren@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7e9055bb
  34. 30 4月, 2018 1 次提交
    • J
      tests: introduce test_unset_prereq, for debugging · 7d0ee47c
      Johannes Schindelin 提交于
      While working on the --convert-graft-file test, I missed that I was
      relying on the GPG prereq, by using output of test cases that were only
      run under that prereq.
      
      For debugging, it was really convenient to force that prereq to be
      unmet, but there was no easy way to do that. So I came up with a way,
      and this patch reflects the cleaned-up version of that way.
      
      For convenience, the following two methods are now supported ways to
      pretend that a prereq is not met:
      
      	test_set_prereq !GPG
      
      and
      
      	test_unset_prereq GPG
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      7d0ee47c
  35. 25 4月, 2018 1 次提交