8f3d9d5ef6
When we look up the repository path from Git, we pass it through cygpath -w to canonicalize it into a Windows path, since Cygwin's Git will give us a Unix-style path. We perform path canonicalization not only on Cygwin, but also on MINGW as well, which include Git Bash, since we want to accept and canonicalize Unix-style paths there as well. Normally, this works great. However, if invoked not from Git Bash, but via the Git for Windows bash.exe command, no locale is set in the environment, despite the locale binary indicating UTF-8 locales. As a result, if non-ASCII character exist in the path name, it tries to encode them in ISO-8850-1. On a standard Unix, where paths are always bytes, defaulting to ISO-8859-1 might be fine, because regardless of the encoding, paths are always bytes and no encoding needs to be performed. On macOS, where the file system and all locales use UTF-8, this is also not a problem, because again, no encoding needs to be done. However, on Windows, where paths are natively stored as UTF-16, this is remarkably unhelpful, since the majority of Unicode code points cannot be represented in ISO-8859-1. Thus, the vast majority of paths are broken by cygpath when the locale is not set. Since we know we always want UTF-8 from cygpath, let's just force that in the environment we pass it. We need to copy the environment since the value we have is shared among all executed subcommands and we don't want to modify other commands' locales, since that would cause error messages to be printed in English instead of the user's locale. Note that before this change, the test would fail because the local working directory was not read, and therefore it would be empty on Windows. |
||
---|---|---|
.. | ||
cmd | ||
fixtures | ||
git-lfs-test-server-api | ||
Makefile | ||
README.md | ||
t-alternates.sh | ||
t-askpass.sh | ||
t-attributes.sh | ||
t-batch-error-handling.sh | ||
t-batch-retries-ratelimit.sh | ||
t-batch-retries.sh | ||
t-batch-transfer.sh | ||
t-batch-unknown-oids.sh | ||
t-checkout.sh | ||
t-cherry-pick-commits.sh | ||
t-chunked-transfer-encoding.sh | ||
t-clean.sh | ||
t-clone-deprecated.sh | ||
t-clone.sh | ||
t-commit-delete-push.sh | ||
t-config.sh | ||
t-content-type.sh | ||
t-credentials-no-prompt.sh | ||
t-credentials.sh | ||
t-custom-transfers.sh | ||
t-dedup.sh | ||
t-duplicate-oids.sh | ||
t-env.sh | ||
t-expired.sh | ||
t-ext.sh | ||
t-extra-header.sh | ||
t-fetch-include.sh | ||
t-fetch-paths.sh | ||
t-fetch-recent.sh | ||
t-fetch-refspec.sh | ||
t-fetch.sh | ||
t-filter-branch.sh | ||
t-filter-process.sh | ||
t-fsck.sh | ||
t-happy-path.sh | ||
t-install-custom-hooks-path-unsupported.sh | ||
t-install-custom-hooks-path.sh | ||
t-install-worktree-unsupported.sh | ||
t-install-worktree.sh | ||
t-install.sh | ||
t-lock.sh | ||
t-locks.sh | ||
t-logs.sh | ||
t-ls-files.sh | ||
t-malformed-pointers.sh | ||
t-mergetool.sh | ||
t-migrate-export.sh | ||
t-migrate-fixup.sh | ||
t-migrate-import-no-rewrite.sh | ||
t-migrate-import.sh | ||
t-migrate-info.sh | ||
t-object-authenticated.sh | ||
t-pointer.sh | ||
t-post-checkout.sh | ||
t-post-commit.sh | ||
t-post-merge.sh | ||
t-pre-push.sh | ||
t-progress-meter.sh | ||
t-progress.sh | ||
t-prune-worktree.sh | ||
t-prune.sh | ||
t-pull.sh | ||
t-push-bad-dns.sh | ||
t-push-failures-local.sh | ||
t-push-failures-remote.sh | ||
t-push-file-with-branch-name.sh | ||
t-push.sh | ||
t-reference-clone.sh | ||
t-resume-http-range.sh | ||
t-resume-tus.sh | ||
t-smudge.sh | ||
t-ssh.sh | ||
t-standalone-file.sh | ||
t-status.sh | ||
t-submodule-lfsconfig.sh | ||
t-submodule-recurse.sh | ||
t-submodule.sh | ||
t-track-attrs.sh | ||
t-track-wildcards.sh | ||
t-track.sh | ||
t-umask.sh | ||
t-uninstall-worktree-unsupported.sh | ||
t-uninstall-worktree.sh | ||
t-uninstall.sh | ||
t-unlock.sh | ||
t-untrack.sh | ||
t-unusual-filenames.sh | ||
t-update.sh | ||
t-upload-redirect.sh | ||
t-verify.sh | ||
t-version.sh | ||
t-worktree.sh | ||
t-zero-len-file.sh | ||
testenv.sh | ||
testhelpers.sh | ||
testlib.sh |
t
This directory contains one of the two types of tests that the Git LFS project
uses to protect against regression. The first, scattered in *_test.go
files
throughout the repository are unit tests, and written in Go, designed to
uncover failures at the unit level.
The second kind--and the one contained in this directory--are integration
tests, which are designed to exercise Git LFS in an end-to-end fashion,
running the git
, and git-lfs
binaries, along with a mock Git server.
You can run all tests in this directory with any of the following:
$ make
$ make test
$ make PROVE_EXTRA_ARGS=-j9 test
Or run a single test (for example, t-checkout.sh
) by any of the following:
$ make ./t-checkout.sh
$ make PROVE_EXTRA_ARGS=-v ./t-checkout.sh
$ ./t-checkout.sh
Alternatively, one can run a selection of tests (via explicitly listing them or making use of the built-in shell globbing) by any of the following:
$ make ./t-*.sh
$ make PROVE_EXTRA_ARGS=-j9 ./t-*.sh
$ ./t-*.sh
Test File(s)
There are a few important kinds of files to know about in the t
directory:
-
cmd/
: contains the source code of binaries that are useful during test time, like the mocked Git server, or the test counting binary. For more about the contents of this directory, see test lifecycle below.The file
t/cmd/testutils.go
is automatically linked and included during the build process of each file incmd
. -
fixtures/
: contains shell scripts that load fixture repositories useful for testing against. -
t-*.sh
: file(s) containing zero or more tests, typically related to a similar topic (c.f,.t/t-push.sh
,t/t-pull.sh
, etc.) -
testenv.sh
: loads environment variables useful during tests. This file is sourced bytestlib.sh
. -
testhelpers.sh
: loads shell functions useful during tests, likesetup_remote_repo
, andclone_repo
. -
testlib.sh
: loads thebegin_test
,end_test
, and similar functions useful for instantiating a particular test.
Test Lifecycle
When a test is run, the following occurs, in order:
-
Missing test binaries are compiled into the
bin
directory in the repository root. Note: this does not include thegit-lfs
binary, which is re-compiled viascript/boostrap
. -
An integration server is started by either (1) the
Makefile
or (2) thecmd/lfstest-count-test.go
program, which keeps track of the number of running tests and starts an integration server any time the number of active tests goes from0
to1
, and stops the server when it goes fromn
to0
. -
After sourcing
t/testlib.sh
(& loadingt/testenv.sh
), each test is run in sequence per file. (In other words, multiple test files can be run in parallel, but the tests in a single file are run in sequence.) -
An individual test will finish, and (if running under
prove
) another will be started in its place. Once all tests are done,t/test_count
will go to0
, and the test server will be torn down.
Test Environment
There are a few environment variables that you can set to change the test suite behavior:
-
GIT_LFS_TEST_DIR=path
- This sets the directory that is used as the current working directory of the tests. By default, this will be in your temp dir. It's recommended that this is set to a directory outside of any Git repository. -
KEEPTRASH=1
- This will leave the local repository data in atmp
directory and the remote repository data intest/remote
.
Also ensure that your noproxy
environment variable contains 127.0.0.1
host,
to allow git commands to reach the local Git server lfstest-gitserver
.
Writing new tests
A new test file should be named t/t-*.sh
, where *
is the topic of Git LFS
being tested. It should look as follows:
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "my test"
(
set -e
# ...
)
end_test