On Fri, Sep 12, 2014 at 8:47 PM, Craig Rodrigues <
rod...@freebsd.org> wrote:
> Hi,
>
> I have a very simple Kyuafile like this:
>
> syntax(2)
> test_suite('first')
> plain_test_program{name='test1.sh'}
>
>
> Is it possible to specify other programs or lua functions which run before
> and
> after test1.sh which can do additional preparation and cleanup on the
> system,
> but are not part of the test script itself?
It's not possible and I'm not even sure it's a good idea to bundle
this in Kyua. As a general consideration, I don't want to have any
testing code in the Kyuafile; previous experiences with code in
Makefiles and elsewhere have proven this to be suboptimal.
In general, such logic belongs in the test program as the test program
is responsible for cleaning up after itself. (In my opinion, Kyua
already does too much trying to clean up mount points in the work
directory, for example, and I'd rather streamline this than add more
special cases to cope with sloppy test programs.)
> I have a suite of test scripts, some of which do some destructive things.
> When the test scripts are run in an automation run, cleanup needs to occur
> after each script runs.
>
> However, when the script is run individually, no cleanup should occur,
> because the individual developer needs to be able to run the script
> and see the system in the "non-cleaned up" state in order to debug the
> problem.
This is the "special case" and as such should be treated accordingly.
A test program should never leave the system in an inconsistent state
unless you explicitly told it to for debugging purposes. As an
alternative, have you considered adding a "DONT_CLEANUP_FOR_DEBUGGING"
environment variable to the test program and use that to determine
whether the cleanup parts should be run or not? Sounds like a simpler
alternative that doesn't require any plumbing.