4
votes

This seems to be very basic question but I am knocked out. How to test those scripts which one has written for hooking purpose.

As we know that script is running in background and only error is throwing back on us by SVN console. I tried with breakpoint but there is nothing I can provide input to the script.

Does anyone got any idea about it. I am writing svn hook script on windows so many already written hook scripts either not running or not giving desired output for example check mime-type and eol script from apache.

1

1 Answers

6
votes

I can give you some advice:

  • You need to print out to STDERR. That's the only way your script will report errors to you. You can use this for actual testing.
  • I wrote my pre-commit script to take both a -t or an -r command line parameter. When executing as a pre-commit hook, I can use the -t parameter to pass in the transaction number. When running it from the command line, I can use the -r parameter and give it a revision number to run against.
  • I also wrote a debug function that allowed me to print out information when I set a -debug command line parameter. I could turn this on and off.
  • If you are actually testing your hook, use a copy of the repository, and make sure that the pre-commit shell script will fail by ending it with an exit code of 2. You'll never commit your transaction, but you'll get messages in your pre-commit script what is going on (that is, if you print everything to STDERR).

You can look at the hook scripts I'm developing to get some ideas. I use the Data::Dumper Perl module which can help print out data structures in my script.