@@ -583,6 +583,150 @@ i -PassThru:$PassThru {
583583 }
584584 }
585585
586+ b " auto-enabling output features" {
587+ t " CodeCoverage.Path auto-enables code coverage" {
588+ $coverageScript = " $PSScriptRoot /CoverageTestFile.ps1"
589+ $coverageOutputPath = [IO.Path ]::GetTempFileName()
590+ Remove-Item $coverageOutputPath - Force
591+
592+ try {
593+ $r = Invoke-Pester - Configuration ([PesterConfiguration ]@ {
594+ Run = @ {
595+ ScriptBlock = {
596+ Describe " auto coverage" {
597+ It " covers script" {
598+ . $coverageScript
599+ }
600+ }
601+ }.GetNewClosure()
602+ PassThru = $true
603+ }
604+ Output = @ {
605+ Verbosity = ' None'
606+ }
607+ CodeCoverage = @ {
608+ Path = $coverageScript
609+ OutputPath = $coverageOutputPath
610+ }
611+ })
612+
613+ $r.CodeCoverage | Verify- NotNull
614+ (Test-Path $coverageOutputPath ) | Verify- True
615+ }
616+ finally {
617+ if (Test-Path $coverageOutputPath ) {
618+ Remove-Item $coverageOutputPath - Force - ErrorAction Ignore
619+ }
620+ }
621+ }
622+
623+ t " CodeCoverage.Enabled = `$ false still disables code coverage" {
624+ $coverageScript = " $PSScriptRoot /CoverageTestFile.ps1"
625+ $coverageOutputPath = [IO.Path ]::GetTempFileName()
626+ Remove-Item $coverageOutputPath - Force
627+
628+ try {
629+ $r = Invoke-Pester - Configuration ([PesterConfiguration ]@ {
630+ Run = @ {
631+ ScriptBlock = {
632+ Describe " disabled coverage" {
633+ It " does not export coverage" {
634+ . $coverageScript
635+ }
636+ }
637+ }.GetNewClosure()
638+ PassThru = $true
639+ }
640+ Output = @ {
641+ Verbosity = ' None'
642+ }
643+ CodeCoverage = @ {
644+ Enabled = $false
645+ Path = $coverageScript
646+ OutputPath = $coverageOutputPath
647+ }
648+ })
649+
650+ $r.CodeCoverage | Verify- Null
651+ (Test-Path $coverageOutputPath ) | Verify- False
652+ }
653+ finally {
654+ if (Test-Path $coverageOutputPath ) {
655+ Remove-Item $coverageOutputPath - Force - ErrorAction Ignore
656+ }
657+ }
658+ }
659+
660+ t " TestResult.OutputPath auto-enables test result export" {
661+ $testResultOutputPath = [IO.Path ]::GetTempFileName()
662+ Remove-Item $testResultOutputPath - Force
663+
664+ try {
665+ $r = Invoke-Pester - Configuration ([PesterConfiguration ]@ {
666+ Run = @ {
667+ ScriptBlock = {
668+ Describe " auto testresult" {
669+ It " exports xml" {
670+ $true | Should - Be $true
671+ }
672+ }
673+ }
674+ PassThru = $true
675+ }
676+ Output = @ {
677+ Verbosity = ' None'
678+ }
679+ TestResult = @ {
680+ OutputPath = $testResultOutputPath
681+ }
682+ })
683+
684+ $r.Result | Verify- Equal ' Passed'
685+ (Test-Path $testResultOutputPath ) | Verify- True
686+ }
687+ finally {
688+ if (Test-Path $testResultOutputPath ) {
689+ Remove-Item $testResultOutputPath - Force - ErrorAction Ignore
690+ }
691+ }
692+ }
693+
694+ t " TestResult.Enabled = `$ false still disables test result export" {
695+ $testResultOutputPath = [IO.Path ]::GetTempFileName()
696+ Remove-Item $testResultOutputPath - Force
697+
698+ try {
699+ $r = Invoke-Pester - Configuration ([PesterConfiguration ]@ {
700+ Run = @ {
701+ ScriptBlock = {
702+ Describe " disabled testresult" {
703+ It " does not export xml" {
704+ $true | Should - Be $true
705+ }
706+ }
707+ }
708+ PassThru = $true
709+ }
710+ Output = @ {
711+ Verbosity = ' None'
712+ }
713+ TestResult = @ {
714+ Enabled = $false
715+ OutputPath = $testResultOutputPath
716+ }
717+ })
718+
719+ $r.Result | Verify- Equal ' Passed'
720+ (Test-Path $testResultOutputPath ) | Verify- False
721+ }
722+ finally {
723+ if (Test-Path $testResultOutputPath ) {
724+ Remove-Item $testResultOutputPath - Force - ErrorAction Ignore
725+ }
726+ }
727+ }
728+ }
729+
586730 b " configuration modified at runtime" {
587731 t " changes at runtime doesn't leak to advanced configuration object" {
588732 $c = [PesterConfiguration ] @ {
0 commit comments