First of all I’m new to PowerShell so please forgive if it is dumb. I wanted to add testing to my script. So I thought about Pester. But I came across an issue.
Unfortunately my prod environment has PowerShell v2 and also I have to have whole script in one file. On my local I have v5 so I can use its benefits while testing. The problem is that my script is a mix of functions and commands and it seems that if I have this:
$here = Split-Path -Parent $MyInvocation.MyCommand.Path $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".") . "$here\$sut"
In .Test.ps1 script then my main script gets executed. Which I don’t want. I would just like to test functions.
I thought that instead of calling script like
. “$here$sut”, In my main script I could place all functions between some comments and substract only this part, run it a then I could write tests, but this seem to be overcomplicating.
Do you have any advice how can I handle this?