[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

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"
        TXN="$2"

        SVNLOOK="/cygdrive/c/Progra~1/Subversion/bin/svnlook.exe"

        function var_svnlook_txn_set ()
        ### for svnlook commands requiring a transaction
        ### $1 = variable name to set
        ### $2 = svnlook subcommand
        {
                export -n $1="`${SVNLOOK} $2 -t \"${TXN}\" \"${REPOS}\"`"
        }

        function message ()
        {
                echo $1 >&2
        }

        var_svnlook_txn_set "AUTHOR" "author"

        ERRORCODE=0

        ### perform any tests on the transaction...

        if [ "${AUTHOR}" = "yourname" ]
        then
            ### call new test version of a script (such as my_checks__new.py)
        else
            ### call the "original" version of a script (such as my_checks.py)
        fi

        ### exit with success or failure...

        if [ "${AUTHOR}" = "yourname" ]; then message "TESTING: Failed because it's ${AUTHOR}"; ERRORCODE=1; fi

        exit ${ERRORCODE}

> -----Original Message-----
> From: Tremal Naik [mailto:tremalnaik@gmail.com]
> Sent: 24 October 2006 14:53
> To: users@subversion.tigris.org
> Subject: How to test a hook script?
>
>
> Hello,
> I'm trying to test a hook script, before I include it in the
> pre-commit script. I should pass the transaction name as an argument.
> How do I know this? Can I use an old transaction? Is it possible
> testing the hook without a real transaction, simulating one?
>
> thanks
>
> --
> TREMALNAIK
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: users-help@subversion.tigris.org

_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service, on behalf of Celoxica Ltd.

This email and any files transmitted with it are confidential and
may be legally privileged. It is intended solely for the use of the
individual or entity to whom it is addressed. If you have received
this in error, please contact the sender and delete the material
immediately. Whilst this email has been swept for viruses, you
should carry out your own virus check before opening any
attachment. Celoxica Ltd accepts no liability for any loss or
damage which may be caused by software viruses or interception
or interruption of this email.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Tue Oct 24 16:46:21 2006

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.