NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Cheat scripts tested by ATF on the programs they use

On Sat, Jun 9, 2012 at 5:26 PM, Silas Silva <> wrote:
> Hi all!
> I have a bunch of scripts that use system or 3rd-party applications like
> cdrecord, mkisofs or rsync.  Since I don't want to test them, I just to
> force them to return 0 when testing scripts that use them.
> In ATF (using atf-sh-api) the way that comes up to me is to make a local
> directory with scripts (that just exit 0) with the same name or those
> programs, put this directory as the first entry of $PATH and remove them
> at the end of my ATF tests.  But this doesn't look very elegant...

That will work just fine.  Every test is run under its own subshell
and test directory, so as long as you create those wrappers in the
current directory, you do not even have to clean anything (files nor
environment) yourself.

Something like:

create_mocks() {
    mkdir mocks

    for tool in cdrecord; do
        echo '#!/bin/sh' >mocks/${tool}
        echo 'exit 0' >>mocks/${tool}
        chmod +x mocks/${tool}


first_test_body() {

    ... do other stuff here ...
    ... no need to clean up path nor files ...

Julio Merino / @jmmv

Home | Main Index | Thread Index | Old Index