Tip: Test changes while continuing to work

This script below lets you test changes while continuing to work on code. Let’s say that your test suite takes quite a while to run (hello, libguestfs). You can do:

$ test-change make check

The script copies the whole current directory into a temporary directory and runs the check in there. You still have to open a new terminal to run the tests, but the tests can go ahead while you continue working.

#!/bin/bash -
# Copy current directory to a temporary,
# then run the test command on that copy,
# and report the results.
# by Richard W.M. Jones <rjones@redhat.com>
#
# Usage (from current directory):
#   test-change command [args ...]
# eg:
#   test-change make check

echo "Copying original directory; wait a moment ..."
d=`mktemp -d`

trap "rm -rf $d" EXIT INT TERM QUIT

cp -a . $d

cd $d

echo "Original directory copied, starting test."
echo "You can carry on working now."
sleep 1

# Run the test command.
"$@"
About these ads

1 Comment

Filed under Uncategorized

One response to “Tip: Test changes while continuing to work

  1. Bob

    Some bugs:

    /bin/bash is bogus; use /usr/bin/env bash in the worst case or /bin/sh in the best case. I can see nothing that is not POSIX here so use /bin/sh

    cp -a . $d should be “$d” out of habbit, although not required by any actual existing mktemp implementations; same with cd $d.

    sleep 1 is pointless here.

    Perhaps this script can detect the use of ZFS and automatically call “zfs snapshot/clone” in order to avoid the slowness of cp?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s