Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Tue, 20 Jul 2010 18:29:30 +0000 (11:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Jul 2010 18:29:30 +0000 (11:29 -0700)
* maint:
t/README: clarify test_must_fail description
Check size of path buffer before writing into it

Conflicts:
t/README

1  2 
setup.c
t/README
diff --combined setup.c
index 87c21f02e0e3bedb42305bbfe2b4223885d4250f,3bb046118cb612b16f35fa016032d1486c6e7190..276916052795c5ffa872b57a7e6723edc71dfdc4
+++ b/setup.c
@@@ -170,6 -170,8 +170,8 @@@ static int is_git_directory(const char 
        char path[PATH_MAX];
        size_t len = strlen(suspect);
  
+       if (PATH_MAX <= len + strlen("/objects"))
+               die("Too long path: %.*s", 60, suspect);
        strcpy(path, suspect);
        if (getenv(DB_ENVIRONMENT)) {
                if (access(getenv(DB_ENVIRONMENT), X_OK))
@@@ -323,9 -325,6 +325,9 @@@ const char *setup_git_directory_gently(
        const char *gitdirenv;
        const char *gitfile_dir;
        int len, offset, ceil_offset, root_len;
 +      dev_t current_device = 0;
 +      int one_filesystem = 1;
 +      struct stat buf;
  
        /*
         * Let's assume that we are in a git repository.
         *   etc.
         */
        offset = len = strlen(cwd);
 +      one_filesystem = !git_env_bool("GIT_DISCOVERY_ACROSS_FILESYSTEM", 0);
 +      if (one_filesystem) {
 +              if (stat(".", &buf))
 +                      die_errno("failed to stat '.'");
 +              current_device = buf.st_dev;
 +      }
        for (;;) {
                gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
                if (gitfile_dir) {
                        }
                        die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
                }
 -              if (chdir(".."))
 +              if (one_filesystem) {
 +                      if (stat("..", &buf)) {
 +                              cwd[offset] = '\0';
 +                              die_errno("failed to stat '%s/..'", cwd);
 +                      }
 +                      if (buf.st_dev != current_device) {
 +                              if (nongit_ok) {
 +                                      if (chdir(cwd))
 +                                              die_errno("Cannot come back to cwd");
 +                                      *nongit_ok = 1;
 +                                      return NULL;
 +                              }
 +                              cwd[offset] = '\0';
 +                              die("Not a git repository (or any parent up to mount parent %s)\n"
 +                              "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd);
 +                      }
 +              }
 +              if (chdir("..")) {
 +                      cwd[offset] = '\0';
                        die_errno("Cannot change to '%s/..'", cwd);
 +              }
        }
  
        inside_git_dir = 0;
diff --combined t/README
index b906ceb4766a283ae6b22bd037f9e1619feb12d1,fecb76e599cee2643e4f6c05c44fa2585e807284..a5901424388b9cfb525b7bdbfd6d5afda3c9e014
+++ b/t/README
@@@ -18,48 -18,25 +18,48 @@@ The easiest way to run tests is to say 
  the tests.
  
      *** t0000-basic.sh ***
 -    *   ok 1: .git/objects should be empty after git-init in an empty repo.
 -    *   ok 2: .git/objects should have 256 subdirectories.
 -    *   ok 3: git-update-index without --add should fail adding.
 +    ok 1 - .git/objects should be empty after git init in an empty repo.
 +    ok 2 - .git/objects should have 3 subdirectories.
 +    ok 3 - success is reported like this
      ...
 -    *   ok 23: no diff after checkout and git-update-index --refresh.
 -    * passed all 23 test(s)
 -    *** t0100-environment-names.sh ***
 -    *   ok 1: using old names should issue warnings.
 -    *   ok 2: using old names but having new names should not issue warnings.
 -    ...
 -
 -Or you can run each test individually from command line, like
 -this:
 -
 -    $ sh ./t3001-ls-files-killed.sh
 -    *   ok 1: git-update-index --add to add various paths.
 -    *   ok 2: git-ls-files -k to show killed files.
 -    *   ok 3: validate git-ls-files -k output.
 -    * passed all 3 test(s)
 +    ok 43 - very long name in the index handled sanely
 +    # fixed 1 known breakage(s)
 +    # still have 1 known breakage(s)
 +    # passed all remaining 42 test(s)
 +    1..43
 +    *** t0001-init.sh ***
 +    ok 1 - plain
 +    ok 2 - plain with GIT_WORK_TREE
 +    ok 3 - plain bare
 +
 +Since the tests all output TAP (see http://testanything.org) they can
 +be run with any TAP harness. Here's an example of parallel testing
 +powered by a recent version of prove(1):
 +
 +    $ prove --timer --jobs 15 ./t[0-9]*.sh
 +    [19:17:33] ./t0005-signals.sh ................................... ok       36 ms
 +    [19:17:33] ./t0022-crlf-rename.sh ............................... ok       69 ms
 +    [19:17:33] ./t0024-crlf-archive.sh .............................. ok      154 ms
 +    [19:17:33] ./t0004-unwritable.sh ................................ ok      289 ms
 +    [19:17:33] ./t0002-gitfile.sh ................................... ok      480 ms
 +    ===(     102;0  25/?  6/?  5/?  16/?  1/?  4/?  2/?  1/?  3/?  1... )===
 +
 +prove and other harnesses come with a lot of useful options. The
 +--state option in particular is very useful:
 +
 +    # Repeat until no more failures
 +    $ prove -j 15 --state=failed,save ./t[0-9]*.sh
 +
 +You can also run each test individually from command line, like this:
 +
 +    $ sh ./t3010-ls-files-killed-modified.sh
 +    ok 1 - git update-index --add to add various paths.
 +    ok 2 - git ls-files -k to show killed files.
 +    ok 3 - validate git ls-files -k output.
 +    ok 4 - git ls-files -m to show modified files.
 +    ok 5 - validate git ls-files -m output.
 +    # passed all 5 test(s)
 +    1..5
  
  You can pass --verbose (or -v), --debug (or -d), and --immediate
  (or -i) command line argument to the test, or by setting GIT_TEST_OPTS
@@@ -221,101 -198,15 +221,101 @@@ This test harness library does the foll
   - If the script is invoked with command line argument --help
     (or -h), it shows the test_description and exits.
  
 - - Creates an empty test directory with an empty .git/objects
 -   database and chdir(2) into it.  This directory is 't/trash directory'
 -   if you must know, but I do not think you care.
 + - Creates an empty test directory with an empty .git/objects database
 +   and chdir(2) into it.  This directory is 't/trash
 +   directory.$test_name_without_dotsh', with t/ subject to change by
 +   the --root option documented above.
  
   - Defines standard test helper functions for your scripts to
     use.  These functions are designed to make all scripts behave
     consistently when command line arguments --verbose (or -v),
     --debug (or -d), and --immediate (or -i) is given.
  
 +Do's, don'ts & things to keep in mind
 +-------------------------------------
 +
 +Here are a few examples of things you probably should and shouldn't do
 +when writing tests.
 +
 +Do:
 +
 + - Put all code inside test_expect_success and other assertions.
 +
 +   Even code that isn't a test per se, but merely some setup code
 +   should be inside a test assertion.
 +
 + - Chain your test assertions
 +
 +   Write test code like this:
 +
 +      git merge foo &&
 +      git push bar &&
 +      test ...
 +
 +   Instead of:
 +
 +      git merge hla
 +      git push gh
 +      test ...
 +
 +   That way all of the commands in your tests will succeed or fail. If
 +   you must ignore the return value of something (e.g. the return
 +   value of export is unportable) it's best to indicate so explicitly
 +   with a semicolon:
 +
 +      export HLAGH;
 +      git merge hla &&
 +      git push gh &&
 +      test ...
 +
 +Don't:
 +
 + - exit() within a <script> part.
 +
 +   The harness will catch this as a programming error of the test.
 +   Use test_done instead if you need to stop the tests early (see
 +   "Skipping tests" below).
 +
 + - Break the TAP output
 +
 +   The raw output from your test may be interpreted by a TAP harness. TAP
 +   harnesses will ignore everything they don't know about, but don't step
 +   on their toes in these areas:
 +
 +   - Don't print lines like "$x..$y" where $x and $y are integers.
 +
 +   - Don't print lines that begin with "ok" or "not ok".
 +
 +   TAP harnesses expect a line that begins with either "ok" and "not
 +   ok" to signal a test passed or failed (and our harness already
 +   produces such lines), so your script shouldn't emit such lines to
 +   their output.
 +
 +   You can glean some further possible issues from the TAP grammar
 +   (see http://search.cpan.org/perldoc?TAP::Parser::Grammar#TAP_Grammar)
 +   but the best indication is to just run the tests with prove(1),
 +   it'll complain if anything is amiss.
 +
 +Keep in mind:
 +
 + - Inside <script> part, the standard output and standard error
 +   streams are discarded, and the test harness only reports "ok" or
 +   "not ok" to the end user running the tests. Under --verbose, they
 +   are shown to help debugging the tests.
 +
 +
 +Skipping tests
 +--------------
 +
 +If you need to skip all the remaining tests you should set skip_all
 +and immediately call test_done. The string you give to skip_all will
 +be used as an explanation for why the test was skipped. for instance:
 +
 +      if ! test_have_prereq PERL
 +      then
 +          skip_all='skipping perl interface tests, perl not available'
 +          test_done
 +      fi
  
  End with test_done
  ------------------
@@@ -331,9 -222,9 +331,9 @@@ Test harness librar
  There are a handful helper functions defined in the test harness
  library for your script to use.
  
 - - test_expect_success <message> <script>
 + - test_expect_success [<prereq>] <message> <script>
  
 -   This takes two strings as parameter, and evaluates the
 +   Usually takes two strings as parameter, and evaluates the
     <script>.  If it yields success, test is considered
     successful.  <message> should state what it is testing.
  
            'git-write-tree should be able to write an empty tree.' \
            'tree=$(git-write-tree)'
  
 - - test_expect_failure <message> <script>
 +   If you supply three parameters the first will be taken to be a
 +   prerequisite, see the test_set_prereq and test_have_prereq
 +   documentation below:
 +
 +      test_expect_success TTY 'git --paginate rev-list uses a pager' \
 +          ' ... '
 +
 + - test_expect_failure [<prereq>] <message> <script>
  
     This is NOT the opposite of test_expect_success, but is used
     to mark a test that demonstrates a known breakage.  Unlike
     success and "still broken" on failure.  Failures from these
     tests won't cause -i (immediate) to stop.
  
 +   Like test_expect_success this function can optionally use a three
 +   argument invocation with a prerequisite as the first argument.
 +
 + - test_expect_code [<prereq>] <code> <message> <script>
 +
 +   Analogous to test_expect_success, but pass the test if it exits
 +   with a given exit <code>
 +
 + test_expect_code 1 'Merge with d/f conflicts' 'git merge "merge msg" B master'
 +
   - test_debug <script>
  
     This takes a single argument, <script>, and evaluates it only
     Merges the given rev using the given message.  Like test_commit,
     creates a tag and calls test_tick before committing.
  
 + - test_set_prereq SOME_PREREQ
 +
 +   Set a test prerequisite to be used later with test_have_prereq. The
 +   test-lib will set some prerequisites for you, e.g. PERL and PYTHON
 +   which are derived from ./GIT-BUILD-OPTIONS (grep test_set_prereq
 +   test-lib.sh for more). Others you can set yourself and use later
 +   with either test_have_prereq directly, or the three argument
 +   invocation of test_expect_success and test_expect_failure.
 +
 + - test_have_prereq SOME PREREQ
 +
 +   Check if we have a prerequisite previously set with
 +   test_set_prereq. The most common use of this directly is to skip
 +   all the tests if we don't have some essential prerequisite:
 +
 +      if ! test_have_prereq PERL
 +      then
 +          skip_all='skipping perl interface tests, perl not available'
 +          test_done
 +      fi
 +
 + - test_external [<prereq>] <message> <external> <script>
 +
 +   Execute a <script> with an <external> interpreter (like perl). This
 +   was added for tests like t9700-perl-git.sh which do most of their
 +   work in an external test script.
 +
 +      test_external \
 +          'GitwebCache::*FileCache*' \
 +          "$PERL_PATH" "$TEST_DIRECTORY"/t9503/test_cache_interface.pl
 +
 +   If the test is outputting its own TAP you should set the
 +   test_external_has_tap variable somewhere before calling the first
 +   test_external* function. See t9700-perl-git.sh for an example.
 +
 +      # The external test will outputs its own plan
 +      test_external_has_tap=1
 +
 + - test_external_without_stderr [<prereq>] <message> <external> <script>
 +
 +   Like test_external but fail if there's any output on stderr,
 +   instead of checking the exit code.
 +
 +      test_external_without_stderr \
 +          'Perl API' \
 +          "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl
 +
   - test_must_fail <git-command>
  
     Run a git command and ensure it fails in a controlled way.  Use
-    this instead of "! <git-command>" to fail when git commands
-    segfault.
+    this instead of "! <git-command>".  When git-command dies due to a
+    segfault, test_must_fail diagnoses it as an error; "! <git-command>"
+    treats it as just another expected failure, which would let such a
+    bug go unnoticed.
  
 + - test_might_fail <git-command>
 +
 +   Similar to test_must_fail, but tolerate success, too.  Use this
 +   instead of "<git-command> || :" to catch failures due to segv.
 +
 + - test_cmp <expected> <actual>
 +
 +   Check whether the content of the <actual> file matches the
 +   <expected> file.  This behaves like "cmp" but produces more
 +   helpful output when the test is run with "-v" option.
 +
 + - test_when_finished <script>
 +
 +   Prepend <script> to a list of commands to run to clean up
 +   at the end of the current test.  If some clean-up command
 +   fails, the test will not pass.
 +
 +   Example:
 +
 +      test_expect_success 'branch pointing to non-commit' '
 +              git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
 +              test_when_finished "git update-ref -d refs/heads/invalid" &&
 +              ...
 +      '
 +
 +
  Tips for Writing Tests
  ----------------------