Commit graph

288 commits

Author SHA1 Message Date
Jeff King 4cd31a6320 Merge branch 'jc/test-say-color-avoid-echo-escape'
Recent nd/wildmatch series was the first to reveal this ancient bug
in the test scaffolding.

* jc/test-say-color-avoid-echo-escape:
  test-lib: Fix say_color () not to interpret \a\b\c in the message
2012-10-25 06:42:49 -04:00
Junio C Hamano 7bc0911d03 test-lib: Fix say_color () not to interpret \a\b\c in the message
When running with color disabled (e.g. under prove to produce TAP
output), say_color() helper function is defined to use echo to show
the message.  With a message that ends with "\c", echo is allowed to
interpret it as "Do not end the line with LF".

Use printf "%s\n" to emit the message literally.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-10-11 10:40:36 -07:00
Junio C Hamano 70dac5f44d Merge branch 'ep/malloc-check-perturb'
Fixes a brown-paper bag bug.

* ep/malloc-check-perturb:
  MALLOC_CHECK: enable it, unless disabled explicitly
2012-10-01 12:59:06 -07:00
Junio C Hamano a275e823ac Merge branch 'rr/test-use-shell-path-not-shell'
Fixes a brown-paper bag bug.

* rr/test-use-shell-path-not-shell:
  test-lib: use $SHELL_PATH, not $SHELL
2012-09-29 22:27:56 -07:00
René Scharfe ee1431bfc5 MALLOC_CHECK: enable it, unless disabled explicitly
The malloc checks in tests are currently disabled.  Actually evaluate
the variable for turning them off and enable them if it's unset.

Also use this opportunity to give it the more descriptive and
consistent name TEST_NO_MALLOC_CHECK.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-26 23:39:13 -07:00
Junio C Hamano 86bdfa3955 Merge branch 'rr/test-make-sure-we-have-git'
Only the first test t0000 in the test suite made sure we have built
Git to be tested; move the check to test-lib so that it applies to
all tests equally.

* rr/test-make-sure-we-have-git:
  t/test-lib: make sure Git has already been built
2012-09-25 10:40:24 -07:00
Ramkumar Ramachandra 4cde519fe6 test-lib: use $SHELL_PATH, not $SHELL
The codepath for handling "--tee" ends up relaunching the test
script under a shell, and that one has to be a Bourne.  But we
incorrectly used $SHELL, which could be a non-Bourne (e.g. zsh or
csh); we have the Makefile variable $SHELL_PATH for exactly that,
so use it instead.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-25 10:17:29 -07:00
Ramkumar Ramachandra 2006f0adae t/test-lib: make sure Git has already been built
When tests were run without building git, they stopped with:

    .: 54: Can't open /path/to/git/source/t/../GIT-BUILD-OPTIONS

Move the check that makes sure that git has already been built from
t0000 to test-lib, so that any test will do so before it runs.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-18 14:22:19 -07:00
Junio C Hamano 1b3185fc2b MALLOC_CHECK: various clean-ups
The most important in this change is to avoid affecting anything
when test-lib is used from perf-lib.  It also limits the effect of
the MALLOC_CHECK only to what is run inside the actual test, and
uses a fixed MALLOC_PERTURB_ in order to avoid hurting repeatability
of the tests.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-17 22:00:27 -07:00
Elia Pinto a731fa916e Add MALLOC_CHECK_ and MALLOC_PERTURB_ libc env to the test suite for detecting heap corruption
Recent versions of Linux libc (later than 5.4.23) and glibc (2.x)
include a malloc() implementation which is tunable via environment
variables. When MALLOC_CHECK_ is set, a special (less efficient)
implementation is used which is designed to be tolerant against
simple errors, such as double calls of free() with the same argument,
or overruns of a single byte (off-by-one bugs). When MALLOC_CHECK_
is set to 3, a diagnostic message is printed on stderr
and the program is aborted.

Setting the MALLOC_PERTURB_ environment variable causes the malloc
functions in libc to return memory which has been wiped and clear
memory when it is returned.
Of course this does not affect calloc which always does clear the memory.

The reason for this exercise is, of course, to find code which uses
memory returned by malloc without initializing it and code which uses
code after it is freed. valgrind can do this but it's costly to run.
The MALLOC_PERTURB_ exchanges the ability to detect problems in 100%
of the cases with speed.

The byte value used to initialize values returned by malloc is the byte
value of the environment value. The value used to clear memory is the
bitwise inverse. Setting MALLOC_PERTURB_ to zero disables the feature.

This technique can find hard to detect bugs.
It is therefore suggested to always use this flag (at least temporarily)
when testing out code or a new distribution.

But the test suite can use also valgrind(memcheck) via 'make valgrind'
or 'make GIT_TEST_OPTS="--valgrind"'.

Memcheck wraps client calls to malloc(), and puts a "red zone" on
each end of each block in order to detect access overruns.
Memcheck already detects double free() (up to the limit of the buffer
which remembers pending free()). Thus memcheck subsumes all the
documented coverage of MALLOC_CHECK_.

If MALLOC_CHECK_ is set non-zero when running memcheck, then the
overruns that might be detected by MALLOC_CHECK_ would be overruns
on the wrapped blocks which include the red zones.  Thus MALLOC_CHECK_
would be checking memcheck, and not the client.  This is not useful,
and actually is wasteful.  The only possible [documented] advantage
of using MALLOC_CHECK_ and memcheck together, would be if MALLOC_CHECK_
detected duplicate free() in more cases than memcheck because memcheck's
buffer is too small.

Therefore we don't use MALLOC_CHECK_ and valgrind(memcheck) at the
same time.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-14 16:05:52 -07:00
Junio C Hamano 0ca416f166 Merge branch 'rj/tap-fix'
* rj/tap-fix:
  test-lib.sh: Suppress the "passed all ..." message if no tests run
  test-lib.sh: Add check for invalid use of 'skip_all' facility
  test-lib.sh: Fix some shell coding style violations
  t4016-*.sh: Skip all tests rather than each test
  t3902-*.sh: Skip all tests rather than each test
  t3300-*.sh: Fix a TAP parse error
2012-09-14 11:53:45 -07:00
Ramsay Jones d87bd7c15b test-lib.sh: Suppress the "passed all ..." message if no tests run
If a test script issues a test_done without executing any tests, for
example when using the 'skip_all' facility, the output looks something
like this:

    $ ./t9159-git-svn-no-parent-mergeinfo.sh
    # passed all 0 test(s)
    1..0 # SKIP skipping git svn tests, svn not found
    $

The "passed all 0 test(s)" comment line, while correct, looks a little
strange. Add a check to suppress this message if no tests have actually
been run.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-02 19:32:31 -07:00
Ramsay Jones bf4b721932 test-lib.sh: Add check for invalid use of 'skip_all' facility
The 'skip_all' facility cannot be used after one or more tests
have been executed using (for example) 'test_expect_success'.
To do so results in invalid TAP output, which leads to 'prove'
complaining of "Parse errors: No plan found in TAP output".

Add a check for such invalid usage and abort the test with an
error message to alert the test author.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-02 19:32:31 -07:00
Ramsay Jones 1c0cc7563b test-lib.sh: Fix some shell coding style violations
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-02 19:32:31 -07:00
Michael J Gruber 5b0b5dd49b test-lib: provide UTF8 behaviour as a prerequisite
UTF8 behaviour of the filesystem (conversion from nfd to nfc)  plays a
role in several tests and is tested in several tests. Therefore, move
the test from t0050 into the test lib and use the prerequisite in t0050.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-27 10:11:14 -07:00
Michael J Gruber ac39aa6121 test-lib: provide case insensitivity as a prerequisite
Case insensitivity plays a role in several tests and is tested in several
tests. Therefore, move the test from t003 into the test lib and use the
prerequisite in t0003.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-27 10:08:33 -07:00
Junio C Hamano 04083f278d test: allow prerequisite to be evaluated lazily
The test prerequisite mechanism is a useful way to allow some tests
in a test script to be skipped in environments that do not support
certain features (e.g. it is pointless to attempt checking how well
symbolic links are handled by Git on filesystems that do not support
them).  It is OK for commonly used prerequisites to be always tested
during start-up of a test script by having a codeblock that tests a
feature and calls test_set_prereq, but for an uncommon feature,
forcing 90% of scripts to pay the same probing overhead for
prerequisite they do not care about is wasteful.

Introduce a mechanism to probe the prerequiste lazily.  Changes are:

 - test_lazy_prereq () function, which takes the name of the
   prerequisite it probes and the script to probe for it, is
   added.  This only registers the name of the prerequiste that can
   be lazily probed and the script to eval (without running).

 - test_have_prereq() function (which is used by test_expect_success
   and also can be called directly by test scripts) learns to look
   at the list of prerequisites that can be lazily probed, and the
   prerequisites that have already been probed that way.  When asked
   for a prerequiste that can be but haven't been probed, the script
   registered with an earlier call to test_lazy_prereq is evaluated
   and the prerequisite is set.

 - test_run_lazy_prereq_() function is a helper to run the probe
   script with the same kind of sandbox as regular tests, helped by
   Jeff King.

Update the codeblock to probe and set SYMLINKS prerequisite using
the new mechanism as an example.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-27 10:07:35 -07:00
Junio C Hamano cdd159b2f5 Merge branch 'jc/test-lib-source-build-options-early'
Reorders t/test-lib.sh so that we dot-source GIT-BUILD-OPTIONS that
records the shell and Perl the user told us to use with Git a lot
early, so that test-lib.sh script itself can use "$PERL_PATH" in
one of its early operations.

* jc/test-lib-source-build-options-early:
  test-lib: reorder and include GIT-BUILD-OPTIONS a lot earlier
2012-07-25 15:47:08 -07:00
Junio C Hamano 0d94427ef8 Merge branch 'mm/config-xdg'
Finishing touches to the XDG support (new feature for 1.7.12) and
tests.

* mm/config-xdg:
  t1306: check that XDG_CONFIG_HOME works
  ignore: make sure we have an xdg path before using it
  attr: make sure we have an xdg path before using it
  test-lib.sh: unset XDG_CONFIG_HOME
2012-07-25 15:47:05 -07:00
Jeff King 5adf84ebb3 test-lib.sh: unset XDG_CONFIG_HOME
Now that git respects XDG_CONFIG_HOME for some lookups, we
must be sure to cleanse the test environment. Otherwise, the
user's XDG_CONFIG_HOME could influence the test results.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-24 08:59:07 -07:00
Junio C Hamano 3c8f12c96c test-lib: reorder and include GIT-BUILD-OPTIONS a lot earlier
This dot-sources GIT-BUILD-OPTIONS a lot earlier in test-lib.sh so
that its use of "perl" can use "$PERL_PATH" to choose the version of
Perl the user told us is suitable for our use.

This is iffy; I didn't check it very carefully, and I would not be
surprised if there are subtle breakages.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-06-24 22:01:35 -07:00
Junio C Hamano 770bf6c5e2 t/test-lib.sh: export PERL_PATH for use in scripts
Most notably, t4031 creates a small shell script that invokes perl
and we want to use "$PERL_PATH" to name the version of Perl suitable
for our use, read from GIT-BUILD-OPTS.  The test would fail when it
is directly run in t/ directory from the shell or "make" is run in t/
directory.

This problem was hidden from "make test" run in the top-level
directory, because its Makefile exports PERL_PATH.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-06-24 21:56:13 -07:00
Junio C Hamano 85dcc3820b Merge branch 'zj/mksh-columns-breakage'
A broken shell may not let us set an environment value to an arbitrary
value, interfering with some of the tests. Introduce a test prerequisite
so that we can skip some tests on such a platform.

By Zbigniew Jędrzejewski-Szmek
* zj/mksh-columns-breakage:
  test-lib: skip test with COLUMNS=1 under mksh
2012-05-02 13:51:53 -07:00
Zbigniew Jędrzejewski-Szmek b082687cba test-lib: skip test with COLUMNS=1 under mksh
mksh does not allow $COLUMNS to be set below 12.  mksh(1) says that
$COLUMNS is "always set, defaults to 80, unless the value as reported
by stty(1) is non-zero and sane enough". This applies also to setting
it directly for one command:

    $ COLUMNS=10 python -c 'import os; print os.environ["COLUMNS"]'
    98

Add a test prerequisite by checking if we can set COLUMNS=1, to allow
us to skip tests that needs it.

Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-27 09:26:37 -07:00
Zbigniew Jędrzejewski-Szmek b1d645b58a tests: unset COLUMNS inherited from environment
$COLUMNS must be unset to not interfere with the tests. The tests
already ignore the terminal size because output is redirected to a
file, but COLUMNS overrides terminal size detection and changes the
test output away from the standard 80.

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-27 07:56:57 -07:00
Junio C Hamano 91527e54d5 Merge branch 'maint'
* maint:
  Update draft release notes to 1.7.9.3 for the last time
  http.proxy: also mention https_proxy and all_proxy
  t0300: work around bug in dash 0.5.6
  t5512 (ls-remote): modernize style
  tests: fix spurious error when run directly with Solaris /usr/xpg4/bin/sh
2012-03-04 22:21:52 -08:00
Stefano Lattarini 661bfd13b4 tests: fix spurious error when run directly with Solaris /usr/xpg4/bin/sh
If any test script is run directly with Solaris 10 /usr/xpg4/bin/sh or
/bin/ksh, it fails spuriously with a message like:

  t0000-basic.sh[31]: unset: bad argument count

This happens because those shells bail out when encountering a call to
"unset" with no arguments, and such unset call could take place in
'test-lib.sh'.  Fix that issue, and add a proper comment to ensure we
don't regress in this respect.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-02 14:41:06 -08:00
Thomas Rast 342e9ef2d9 Introduce a performance testing framework
This introduces a performance testing framework under t/perf/.  It
tries to be as close to the test-lib.sh infrastructure as possible,
and thus should be easy to get used to for git developers.

The following points were considered for the implementation:

1. You usually want to compare arbitrary revisions/build trees against
   each other.  They may not have the performance test under
   consideration, or even the perf-lib.sh infrastructure.

   To cope with this, the 'run' script lets you specify arbitrary
   build dirs and revisions.  It even automatically builds the revisions
   if it doesn't have them at hand yet.

2. Usually you would not want to run all tests.  It would take too
   long anyway.  The 'run' script lets you specify which tests to run;
   or you can also do it manually.  There is a Makefile for
   discoverability and 'make clean', but it is not meant for
   real-world use.

3. Creating test repos from scratch in every test is extremely
   time-consuming, and shipping or downloading such large/weird repos
   is out of the question.

   We leave this decision to the user.  Two different sizes of test
   repos can be configured, and the scripts just copy one or more of
   those (using hardlinks for the object store).  By default it tries
   to use the build tree's git.git repository.

   This is fairly fast and versatile.  Using a copy instead of a clone
   preserves many properties that the user may want to test for, such
   as lots of loose objects, unpacked refs, etc.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17 08:21:22 -08:00
Thomas Rast 12a29b1a50 Move the user-facing test library to test-lib-functions.sh
This just moves all the user-facing functions to a separate file and
sources that instead.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17 08:11:29 -08:00
Junio C Hamano e06ed3ed8a Merge branch 'jk/tests-write-script'
* jk/tests-write-script:
  t0300: use write_script helper
  tests: add write_script helper function
2012-02-10 14:07:42 -08:00
Junio C Hamano 840c519d7e tests: add write_script helper function
Many of the scripts in the test suite write small helper
shell scripts to disk. It's best if these shell scripts
start with "#!$SHELL_PATH" rather than "#!/bin/sh", because
/bin/sh on some platforms is too buggy to be used.

However, it can be cumbersome to expand $SHELL_PATH, because
the usual recipe for writing a script is:

	cat >foo.sh <<-\EOF
	#!/bin/sh
	echo my arguments are "$@"
	EOF

To expand $SHELL_PATH, you have to either interpolate the
here-doc (which would require quoting "\$@"), or split the
creation into two commands (interpolating the $SHELL_PATH
line, but not the rest of the script). Let's provide a
helper function that makes that less syntactically painful.

While we're at it, this helper can also take care of the
"chmod +x" that typically comes after the creation of such a
script, saving the caller a line.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-03 23:01:07 -08:00
Junio C Hamano af6b37fab1 Merge branch 'jc/pull-signed-tag'
* jc/pull-signed-tag:
  merge: use editor by default in interactive sessions

Conflicts:
	Documentation/merge-options.txt
2012-01-31 22:30:42 -08:00
Junio C Hamano f8246281af merge: use editor by default in interactive sessions
Traditionally, a cleanly resolved merge was committed by "git merge" using
the auto-generated merge commit log message without invoking the editor.

After 5 years of use in the field, it turns out that people perform too
many unjustified merges of the upstream history into their topic branches.
These merges are not just useless, but they are often not explained well,
and making the end result unreadable when it gets time for merging their
history back to their upstream.

Earlier we added the "--edit" option to the command, so that people can
edit the log message to explain and justify their merge commits. Let's
take it one step further and spawn the editor by default when we are in an
interactive session (i.e. the standard input and the standard output are
pointing at the same tty device).

There may be existing scripts that leave the standard input and the
standard output of the "git merge" connected to whatever environment the
scripts were started, and such invocation might trigger the above
"interactive session" heuristics.  GIT_MERGE_AUTOEDIT environment variable
can be set to "no" at the beginning of such scripts to use the historical
behaviour while the script runs.

Note that this backward compatibility is meant only for scripts, and we
deliberately do *not* support "merge.edit = yes/no/auto" configuration
option to allow people to keep the historical behaviour.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-01-23 14:34:55 -08:00
Jens Lehmann c4d2539af7 test-lib: add the test_pause convenience function
Since 781f76b15 (test-lib: redirect stdin of tests) you can't simply put a
"bash &&" into a test for debugging purposes anymore. Instead you'll have
to use "bash <&6 >&3 2>&4".

As that invocation is not that easy to remember add the test_pause
convenience function. It invokes "$SHELL_PATH" to provide a sane shell
for the user.

This function also checks if the -v flag is given and will error out if
that is not the case instead of letting the test hang until ^D is pressed.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-01-17 15:15:35 -08:00
Junio C Hamano 52b9d2cf7f Merge branch 'jk/maint-do-not-feed-stdin-to-tests'
* jk/maint-do-not-feed-stdin-to-tests:
  test-lib: redirect stdin of tests
2011-12-22 11:27:25 -08:00
Junio C Hamano 2dccad3c6f Merge branch 'ab/enable-i18n'
* ab/enable-i18n:
  i18n: add infrastructure for translating Git with gettext

Conflicts:
	Makefile
2011-12-19 16:06:41 -08:00
Jeff King 781f76b158 test-lib: redirect stdin of tests
We want to run tests in a predictable, sterile environment
so we can get repeatable results.  They should take as
little input as possible from the environment outside the
test script. We already sanitize environment variables, but
leave stdin untouched. This means that scripts can
accidentally be impacted by content on stdin, or whether
stdin isatty().

Furthermore, scripts reading from stdin can be annoying to
outer loops which care about their stdin offset, like:

  while read sha1; do
      make test
  done

A test which accidentally reads stdin would soak up all of
the rest of the input intended for the outer shell loop.

Let's redirect stdin from /dev/null, which solves both
of these problems. It won't detect tests accidentally
reading from stdin, but since doing so now gives a
deterministic result, we don't need to consider that an
error.

We'll also leave file descriptor 6 as a link to the original
stdin. Tests shouldn't need to look at this, but it can be
convenient for inserting interactive commands while
debugging tests (e.g., you could insert "bash <&6 >&3 2>&4"
to run interactive commands in the environment of the test
script).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-15 10:15:07 -08:00
Jeff King a96250c6fb test-lib: add test_config_global variant
The point of test_config is to simultaneously set a config
variable and register its cleanup handler, like:

  test_config core.foo bar

However, it stupidly assumes that $1 contained the name of
the variable, which means it won't work for:

  test_config --global core.foo bar

We could try to parse the command-line ourselves and figure
out which parts need to be fed to test_unconfig. But since
this is likely the most common variant, it's much simpler
and less error-prone to simply add a new function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-11 23:16:24 -08:00
Ævar Arnfjörð Bjarmason 5e9637c629 i18n: add infrastructure for translating Git with gettext
Change the skeleton implementation of i18n in Git to one that can show
localized strings to users for our C, Shell and Perl programs using
either GNU libintl or the Solaris gettext implementation.

This new internationalization support is enabled by default. If
gettext isn't available, or if Git is compiled with
NO_GETTEXT=YesPlease, Git falls back on its current behavior of
showing interface messages in English. When using the autoconf script
we'll auto-detect if the gettext libraries are installed and act
appropriately.

This change is somewhat large because as well as adding a C, Shell and
Perl i18n interface we're adding a lot of tests for them, and for
those tests to work we need a skeleton PO file to actually test
translations. A minimal Icelandic translation is included for this
purpose. Icelandic includes multi-byte characters which makes it easy
to test various edge cases, and it's a language I happen to
understand.

The rest of the commit message goes into detail about various
sub-parts of this commit.

= Installation

Gettext .mo files will be installed and looked for in the standard
$(prefix)/share/locale path. GIT_TEXTDOMAINDIR can also be set to
override that, but that's only intended to be used to test Git itself.

= Perl

Perl code that's to be localized should use the new Git::I18n
module. It imports a __ function into the caller's package by default.

Instead of using the high level Locale::TextDomain interface I've
opted to use the low-level (equivalent to the C interface)
Locale::Messages module, which Locale::TextDomain itself uses.

Locale::TextDomain does a lot of redundant work we don't need, and
some of it would potentially introduce bugs. It tries to set the
$TEXTDOMAIN based on package of the caller, and has its own
hardcoded paths where it'll search for messages.

I found it easier just to completely avoid it rather than try to
circumvent its behavior. In any case, this is an issue wholly
internal Git::I18N. Its guts can be changed later if that's deemed
necessary.

See <AANLkTilYD_NyIZMyj9dHtVk-ylVBfvyxpCC7982LWnVd@mail.gmail.com> for
a further elaboration on this topic.

= Shell

Shell code that's to be localized should use the git-sh-i18n
library. It's basically just a wrapper for the system's gettext.sh.

If gettext.sh isn't available we'll fall back on gettext(1) if it's
available. The latter is available without the former on Solaris,
which has its own non-GNU gettext implementation. We also need to
emulate eval_gettext() there.

If neither are present we'll use a dumb printf(1) fall-through
wrapper.

= About libcharset.h and langinfo.h

We use libcharset to query the character set of the current locale if
it's available. I.e. we'll use it instead of nl_langinfo if
HAVE_LIBCHARSET_H is set.

The GNU gettext manual recommends using langinfo.h's
nl_langinfo(CODESET) to acquire the current character set, but on
systems that have libcharset.h's locale_charset() using the latter is
either saner, or the only option on those systems.

GNU and Solaris have a nl_langinfo(CODESET), FreeBSD can use either,
but MinGW and some others need to use libcharset.h's locale_charset()
instead.

=Credits

This patch is based on work by Jeff Epler <jepler@unpythonic.net> who
did the initial Makefile / C work, and a lot of comments from the Git
mailing list, including Jonathan Nieder, Jakub Narebski, Johannes
Sixt, Erik Faye-Lund, Peter Krefting, Junio C Hamano, Thomas Rast and
others.

[jc: squashed a small Makefile fix from Ramsay]

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-05 20:46:55 -08:00
Junio C Hamano c4800a3b77 Merge branch 'tr/mergetool-valgrind'
* tr/mergetool-valgrind:
  Symlink mergetools scriptlets into valgrind wrappers
2011-10-05 12:35:53 -07:00
Thomas Rast ee0d7bf925 Symlink mergetools scriptlets into valgrind wrappers
Since bc7a96a (mergetool--lib: Refactor tools into separate files,
2011-08-18) the mergetools and difftools related tests fail under
--valgrind because the mergetools/* scriptlets are not in the exec
path.

For now, symlink the mergetools subdir into the t/valgrind/bin
directory as a whole, since it does not contain anything of interest
to the valgrind wrappers.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-30 12:27:01 -07:00
Junio C Hamano f946b465d7 Merge branch 'jk/color-and-pager'
* jk/color-and-pager:
  want_color: automatically fallback to color.ui
  diff: don't load color config in plumbing
  config: refactor get_colorbool function
  color: delay auto-color decision until point of use
  git_config_colorbool: refactor stdout_is_tty handling
  diff: refactor COLOR_DIFF from a flag into an int
  setup_pager: set GIT_PAGER_IN_USE
  t7006: use test_config helpers
  test-lib: add helper functions for config
  t7006: modernize calls to unset

Conflicts:
	builtin/commit.c
	parse-options.c
2011-08-28 21:19:16 -07:00
Junio C Hamano 6fcb384869 Merge branch 'rt/zlib-smaller-window'
* rt/zlib-smaller-window:
  test: consolidate definition of $LF
  Tolerate zlib deflation with window size < 32Kb
2011-08-23 15:40:33 -07:00
Jeff King d960c47a88 test-lib: add helper functions for config
There are a few common tasks when working with configuration
variables in tests; this patch aims to make them a little
easier to write and less error-prone.

When setting a variable, you should typically make sure to
clean it up after the test is finished, so as not to pollute
other tests. Like:

   test_when_finished 'git config --unset foo.bar' &&
   git config foo.bar baz

This patch lets you just write:

  test_config foo.bar baz

When clearing a variable that does not exist, git-config
will report a specific non-zero error code. Meaning that
tests which call "git config --unset" often either rely on
the prior tests having actually set it, or must use
test_might_fail. With this patch, the previous:

  test_might_fail git config --unset foo.bar

becomes:

  test_unconfig foo.bar

Not only is this easier to type, but it is more robust; it
will correctly detect errors from git-config besides "key
was not set".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-18 14:08:54 -07:00
Junio C Hamano 3f4ab62714 test: consolidate definition of $LF
As we seem to need this variable that holds a single LF character
in many places, define it in test-lib.sh and let the test scripts
use it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-11 13:02:47 -07:00
Jonathan Nieder a7c58f280a test: cope better with use of return for errors
In olden times, tests would quietly exit the script when they failed
at an inconvenient moment, which was a little disconcerting.
Therefore v0.99.5~24^2~4 (Trapping exit in tests, using return for
errors, 2005-08-10) switched to an idiom of using "return" instead,
wrapping evaluation of test code in a function to make that safe:

	test_run_ () {
		eval >&3 2>&4 "$1"
		eval_ret="$?"
		return 0
	}

Years later, the implementation of test_when_finished (v1.7.1.1~95,
2010-05-02) and v1.7.2-rc2~1^2~13 (test-lib: output a newline before
"ok" under a TAP harness, 2010-06-24) took advantage of test_run_ as a
place to put code shared by all test assertion functions, without
paying attention to the function's former purpose:

	test_run_ () {
		...
		eval >&3 2>&4 "$1"
		eval_ret=$?

		if should run cleanup
		then
			eval >&3 2>&4 "$test_cleanup"
		fi
		if TAP format requires a newline here
		then
			echo
		fi
		return 0
	}

That means cleanup commands and the newline to put TAP output at
column 0 are skipped when tests use "return" to fail early.  Fix it by
introducing a test_eval_ function to catch the "return", with a
comment explaining the new function's purpose for the next person who
might touch this code.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-08 11:28:42 -07:00
Jonathan Nieder aa0bcf962a test: simplify return value of test_run_
As v0.99.5~24^2~4 (Trapping exit in tests, using return for errors,
2005-08-10) explains, callers to test_run_ (such as test_expect_code)
used to check the result from eval and the return value separately so
tests that fail early could be distinguished from tests that completed
normally with successful (nonzero) status.  Eventually tests that
succeed with nonzero status were phased out (see v1.7.4-rc0~65^2~19,
2010-10-03 and especially v1.5.5-rc0~271, 2008-02-01) but the weird
two-return-value calling convention lives on.

Let's get rid of it.  The new rule: test_run_ succeeds (returns 0)
if and only if the test succeeded.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-08 11:26:40 -07:00
Junio C Hamano f5cfd52f7b Merge branch 'maint-1.7.5' into maint
* maint-1.7.5:
  test: skip clean-up when running under --immediate mode
  "branch -d" can remove more than one branches
2011-06-29 16:41:55 -07:00
Junio C Hamano b586744a86 test: skip clean-up when running under --immediate mode
Some tests try to be too careful about cleaning themselves up and
do

    test_expect_success description '
        set-up some test refs and/or configuration &&
        test_when_finished "revert the above changes" &&
	the real test
    '

Which is nice to make sure that a potential failure would not have
unexpected interaction with the next test. This however interferes when
"the real test" fails and we want to see what is going on, by running the
test with --immediate mode and descending into its trash directory after
the test stops. The precondition to run the real test and cause it to fail
is all gone after the clean-up procedure defined by test_when_finished is
done.

Update test_run_ which is the workhorse of running a test script
called from test_expect_success and test_expect_failure, so that we do not
run clean-up script defined with test_when_finished when a test that is
expected to succeed fails under the --immediate mode.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Jeff King <peff@peff.net>
2011-06-29 16:38:09 -07:00
Jeff King 36bfb0e5f6 tests: link shell libraries into valgrind directory
When we run tests under valgrind, we symlink anything
executable that starts with git-* or test-* into a special
valgrind bin directory, and then make that our
GIT_EXEC_PATH.

However, shell libraries like git-sh-setup do not have the
executable bit marked, and did not get symlinked.  This
means that any test looking for shell libraries in our
exec-path would fail to find them, even though that is a
fine thing to do when testing against a regular git build
(or in a git install, for that matter).

t2300 demonstrated this problem. The fix is to symlink these
shell libraries directly into the valgrind directory.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-17 13:48:53 -07:00