Skip to content
Joshua Mervine edited this page Nov 4, 2013 · 1 revision

Extending Shunt is fairly simple. Creating new assertions is as simple as creating a new bash function and sourcing the include.

Start by creating a file: ./myAssertions.sh and adding a function to it.

# file: myAssertions.sh

# assertion to check that the current checkout's sha matches
# the sha requested
function assert_sha {
  # expected arguments
  sha=$1
  msg=$2

  # test your assertion
  [ "$1" = "$(git rev-parse HEAD)" ]

  # pass results and message to shunt.sh 
  # process function
  process "$?" "$msg"
}

In the above example, assert_sha will only evaluate as true if the full sha (e.g. 85e17cabc32d9cc66daa83d95924267f820055d1) matches perfectly. But let's say you also want to support git's truncated sha handling. We could in stead so something like this:

# file: myAssertions.sh

# assertion to check that the current checkout's sha matches
# the sha requested
function assert_sha {
  # expected arguments
  sha=$1
  msg=$2

  # test your assertion
  git rev-parse HEAD | grep "^$sha" 2>&1 > /dev/null
    # This ensure's that the sha starts with the passed
    # value and hides both STDOUT and STDOUT from being
    # displayed, to keep things pretty.

  # pass results and message to shunt's 
  # process function
  process "$?" "$msg"
}

Now, it's use our custom assertion in myTest.sh:

# file: myTest.sh

# first we source our custom assertions
source ./myAssertions.sh

function run_tests {
  assert_sha "85e17cabc32d9cc66daa83d95924267f820055d1" \
               "sha did not match"
}

And run like so:

./shunt.sh ./myTest.sh

Enjoy!

Clone this wiki locally