On Jun 9, 3:18 am, Mike Schinkel <mikeschin...@gmail.com> wrote:
> Is there a standard way to embed a testing method within a script?
> What I'm looking for is something similar to the idiom you seen in
> Python at the bottom of .py files to include a component for testing?
> In Python it is often used for creating an entry point for something
> that might otherwise be used as a function library, but it can also be
> used for testing.
>
> if __name__ == '__main__':
> Do_something()
>
> I'm trying to implement something like this but it is very verbose and
> feels kludgy.
>
> -Mike
I suppose it depends on the script.

If it's basically expressed as
a series of functions, it's pretty easy to call them individually by
adding this entry point immediately below the last function statement:
if ($args[0] -ne $null) { &$args[0] ; exit }
Then test individual functions like so: foo-bar.ps1 {function1 arg1
arg2 etc}. Or make a special test function that calls a set of other
functions in a specific order, etc. I've found that in some cases,
it's very handy to write whole scripts as linked functions because of
the flexibility it gives in situations like this.
Otherwise there's the -whatif switch.
-Hecks