RE: How to test a hook script?
From: Rob Hubbard <Rob.Hubbard_at_celoxica.com>
Date: 2006-10-24 16:45:08 CEST
Tremal,
You could use real commit tests, but get the script to always fail when it's you, whilst you're adjusting any scripts.
Following is a draft extract from a Bash script (for Linux, or to be called from pre-commit.bat in Cygwin on Windows). You would obviously need to substitute your username for "username", and add your code or calls to the code to be tested.
Essentially, you use "svnlook author" on the transaction to determine the user. If the user is "tremalnaik" (or whatever your subversion username is) then you always return a non-zero value (failure). You can also use this to call a test version of another called script or function, so that you do not affect other users whilst you're testing and debugging. If a called script or function fails, then it should call "message" with some helpful message, and set the ERRORCODE variable to a non-zero value.
When you've finished, you just #comment out the "username"-specific lines.
It's fairly crude, but it works.
This method requires that usernames are used, rather than anonymous access.
I'm sure that there are many alternative strategies, such as using a special "svn-tester" username. I'd be interested to see what other subversion admins do...
Rob.
#!/bin/bash
### pre-commit.sh
REPOS="$1"
SVNLOOK="/cygdrive/c/Progra~1/Subversion/bin/svnlook.exe"
function var_svnlook_txn_set ()
function message ()
var_svnlook_txn_set "AUTHOR" "author"
ERRORCODE=0
### perform any tests on the transaction...
if [ "${AUTHOR}" = "yourname" ]
### exit with success or failure...
if [ "${AUTHOR}" = "yourname" ]; then message "TESTING: Failed because it's ${AUTHOR}"; ERRORCODE=1; fi
exit ${ERRORCODE}
> -----Original Message-----
_____________________________________________________________________
This email and any files transmitted with it are confidential and
---------------------------------------------------------------------
|
This is an archived mail posted to the Subversion Users mailing list.
This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.