Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Embedded testing method in scripts?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-08-2007   #1 (permalink)
Mike Schinkel
Guest


 

Embedded testing method in scripts?

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


My System SpecsSystem Spec
Old 06-09-2007   #2 (permalink)
hecks@hotmail.co.uk
Guest


 

Re: Embedded testing method in scripts?

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


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded HTA David Bray VB Script 10 07-24-2008 05:51 PM
Method invocation failed because [System.String] doesn't contain a method B Williams PowerShell 0 03-31-2008 06:00 PM
Embedded swf does not execute Ralph W Vista mail 1 06-11-2007 02:50 PM
Color of WMP Embedded Muffin Vista music pictures video 0 02-22-2007 07:55 AM
Updated: PowerShell Scripts for Testing Adam Geras PowerShell 2 02-07-2007 05:02 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51