Giter VIP home page Giter VIP logo

git-test's Introduction

git-test -- test your commits

Run tests on each distinct tree in a revision list, skipping versions whose contents have already been tested.

The 99% example is simply:

git test -v

By default it uses heuristics to try to determine what "local commits" to test, but you can supply another ref spec. git-test looks at each commit and checks the hash of the directory tree against the cache. You can also configure a ref (usually a branch) to test against, per repo or or per branch.

From the point of view of git-test, a test can be any shell command and a test is considered successful if that shell command returns with a 0 exit status. This means git-test can be used both for specialised tests of a single feature or failure mode or for running a comprehensive set of automated tests. The cache is keyed on both directory tree and test, so it won't confuse the unit tests with the integration tests, or a specific regression test.

Motivation

An important design goal for git-test has been to make it convenient to use.

Ideally, you should have a work flow where you run your unit tests whenever you save and run unit tests on all your local commits whenever you've done something with version control.

For ease, git-test offers a few advantages over a simple for loop over a git rev-list:

  • By default it spends some effort on working out which commits to test.
  • Cached results, which are keyed to tree contents, rather than commit. This means that commits can be amended or reordered, but only content trees that have never been tested before will be tested.
  • Separate pre- and post-action hooks, the results of which don't actually factor into the test result. (Useful if cleaning fails if there is nothing to clean, for instance.)
  • Configuration of housekeeping and verification steps using
    • git config,
    • environment variables or
    • command line arguments
  • Selective redo, for where you trust failures but not successes, vice versa, or trust nothing.
  • Save output (both STDOUT and STDERR) from cleaning and verifying to an easily referenced symlink farm.

Configure

Mostly just this:

git config test.verify "test command that returns nonzero on fail"

to default to testing against origin/master:

git config test.branch origin/master

to do the same, but for a single branch:

git config branch.mybranch.test parentbranch

Self-Test

To try the test script with different shells:

for sh in /bin/dash /bin/bash /bin/ksh /bin/mksh /bin/pdksh; do
    echo $sh
    sh test.sh -s $sh
done

Note that since version 1.0.2, the shebang is set to /bin/bash. Other shells are now supported on a "patches welcome" basis. (This is largely because I couldn't find a shell I could run in my GNU/Linux environment that behaves like the OS X (FreeBSD?) sh shell, which has very different behaviour from all the others.)

To regression test properly:

rev=$(git rev-parse --short HEAD)
cp test.sh regressions_${rev}.sh
GIT_TEST_VERIFY="sh regressions_${rev}.sh" git test -v

(The reason for copying the script is to test each commit against the new tests, and the reason for naming it based on the current commit is to key the cache correctly.)

Installation

You can just have the git-test script in your PATH, but there are other options:

Homebrew (on OS X)

If you have Homebrew installed, you can install git-test with:

$ brew install git-test

From source

Aside from the packaging, you can also install from source. It's a single POSIX shell script that uses core git, so all that's required for plain git test to work (besides git, of course) is that git-test needs to be somewhere in your PATH (or GIT_EXEC_PATH).

You can install from source by doing the following:

$ install git-test   /usr/local/bin
$ install git-test.1 /usr/local/share/man1

Or just add this directory to your PATH environment variable.

Debian GNU/Linux

The usual

$ fakeroot debian/rules binary

Should give you a Debian package.

Arch Linux

With Arch Linux, you can use the provided PKGBUILD file. Simply download the file and run makepkg in the same directory as the file. It will always build the latest git version of this package, even if you have an old checkout.

git-test's People

Contributors

aes avatar dflemstr avatar efueger avatar olivia5k avatar ravenexp avatar wjlroe avatar zearin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-test's Issues

test regression from github markdown change

b5c08b4

seems to have introduced a regression when running brew test git-test.

The homebrew test runs

  test do
    system "git", "init"
    ln_s "#{bin}/git-test", testpath
    cp "#{share}/test.sh", testpath
    chmod 0755, "test.sh"
    system "git", "add", "test.sh"
    system "git", "commit", "-m", "initial commit"
    ENV["TERM"] = "xterm"
    system "#{bin}/git-test", "-v", "HEAD", "--verify='./test.sh'"
  end

The failure looks like this:

==> /usr/local/Cellar/git-test/HEAD-6fb40ef/bin/git-test -v HEAD --verify='./test.sh'
HEAD will test 1 commits
--
--
0000 | ae14608 | 921ab32 | fail

Full output: https://gist.github.com/ilovezfs/a3d6b4f2ef840e1a009431f10467092a

Manually running test.sh, you get this: https://gist.github.com/ilovezfs/60bce6cd3d07200a6a8e42e1e50f8b9f

The two failed tests are from
here

info "Should show commit table header"
$PROJECT --clear                                >/dev/null 2>&1 ; check
$PROJECT -v --verify=true                            >out 2>err ; check
grep "^iter.*commit.*tree.*result$" out err     >/dev/null 2>&1 ; check

and here

info "Should not confuse files and branches"
$PROJECT --clear                                >/dev/null 2>&1 ; check
git checkout -b subject                         >/dev/null 2>&1 ; check
add_commit "x" "differentiate branches"         >/dev/null 2>&1 ; check
$PROJECT -v --verify=true subject ^master       >out 2>err ; check
grep "^iter.*commit.*tree.*result$" out err     >/dev/null 2>&1 ; check

The problem seems to be that instead of printing "iter .." it just prints "--". Looking at the commit that introduced the regression,

-   gettext "iter commit  tree    result"
+   gettext -- "iter | commit  | tree    | result"

Removing the -- causes the test to pass. I'm not sure what the intent of the -- was but it seems not to be doing the right thing.

Also in the same commit the -- is used again

+   gettext -- "-----|---------|---------|--------------"

That doesn't cause test failure, but may also be incorrect.

Table header missing

The commit table header is not shown, because gettext doesn't emit a newline at the end. The progress output lines start by emitting CR, so the header is overwritten.

Configuring default target branch

When having set up your branches to always track the same remote, running tests against the master (to test all commits in your branch) is a bit cumbersome.

You always have to run git test -v HEAD ^origin/master

It'd be nice to be able to set a default target branch/commit to test against, or a shorthand to test all commits since the merge-base

Add `v1.0.4` tag to commit 3e691bbef63a0247d6383160841bf79014dff645

This is a request to add a git tag v1.0.4 to commit 3e691bb.

Tags are necessary for GitHub to publish Releases, and also relied upon by other tools to track the latest version of git-test.  As it stands, the latest version of git-test that Homebrew can install/update-to is v1.0.2, since that's currently the numerically highest tag.

Lock directory warning misbehaves

"There's a lock dir, as if there is a git-test already in progress.(lock: .git/test-cache/testing)" should be

"There's a lock dir, as if there is a git-test already in progress.
(lock: .git/test-cache/testing)
"

More importantly, it shouldn't remove the lock dir... does it do that now? (Hint: git-test failed because of interaction with rebase)

Add `v1.0.3` tag to commit 5d344d1adacbf6c482701096f140bb1cacafde16

This is a request to add a git tag v1.0.3 to commit 5d344d1.

Tags are necessary for GitHub to publish Releases, and also relied upon by other tools to track the latest version of git-test.  As it stands, the latest version of git-test that Homebrew can install/update-to is v1.0.2, since that's currently the numerically highest tag.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.