Skip to content

Commit

Permalink
Syntax Errors in Tests should be more clear in summary
Browse files Browse the repository at this point in the history
Fixes #172
  • Loading branch information
JustinGrote committed Jul 31, 2023
1 parent 095bbb1 commit 4e0d62f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Scripts/PesterTestPlugin.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using namespace Pester
using namespace System.Management.Automation
using namespace System.Collections
using namespace System.Collections.Generic
using namespace System.IO
Expand Down Expand Up @@ -292,6 +293,12 @@ function New-TestObject ($Test) {
if ($Test.ErrorRecord) {
if ($Test -is [Pester.Block]) {
[String]$DiscoveryError = $Test.ErrorRecord
# Better formatting of parsing errors
if ($Test.ErrorRecord.Exception -is [ParseException]) {
$FirstParseError = $Test.ErrorRecord.Exception.Errors[0]
$firstParseMessage = "Line $($FirstParseError.Extent.StartScriptPosition.LineNumber): $($FirstParseError.Message)"
$DiscoveryError = $firstParseMessage + ([Environment]::NewLine * 2) + $Test.ErrorRecord
}
} else {
#TODO: Better handling once pester adds support
#Reference: https://github.com/pester/Pester/issues/1993
Expand Down

0 comments on commit 4e0d62f

Please sign in to comment.