Skip to content

Commit

Permalink
✅ Adds new koan validation tests (#246)
Browse files Browse the repository at this point in the history
* Adds new koan validation tests. Fixes position.

* Update Tests/KoanValidation.Tests.ps1

Co-Authored-By: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com>
  • Loading branch information
indented-automation and vexx32 committed Sep 13, 2019
1 parent 47e75aa commit 9c2c5f7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion PSKoans/Koans/Cmdlets 1/AboutCompareObject.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 205)]
[Koan(Position = 204)]
param()
<#
Compare-Object
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Cmdlets 1/AboutNewObject.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 204)]
[Koan(Position = 203)]
param()
<#
New-Object
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Cmdlets 1/AboutSelectObject.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 206)]
[Koan(Position = 205)]
param()
<#
Select-Object
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Katas/SortingCharacters.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 115)]
[Koan(Position = 151)]
param()

<#
Expand Down
2 changes: 1 addition & 1 deletion PSKoans/Koans/Katas/TheStockChallenge.Koans.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using module PSKoans
[Koan(Position = 114)]
[Koan(Position = 150)]
param()
<#
Apply Your Knowledge!
Expand Down
43 changes: 39 additions & 4 deletions Tests/KoanValidation.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
using module ..\PSKoans\PSKoans.psd1

$ProjectRoot = Resolve-Path "$PSScriptRoot/.."
$KoanFolder = $ProjectRoot | Join-Path -ChildPath 'PSKoans' | Join-Path -ChildPath 'Koans'

Describe "Koan Assessment" {

$Scripts = Get-ChildItem -Path $KoanFolder -Recurse -Filter '*.Koans.ps1'

# TestCases are splatted to the script so we need hashtables
$TestCases = $Scripts | ForEach-Object { @{File = $_ } }
BeforeAll {
# TestCases are splatted to the script so we need hashtables
$TestCases = InModuleScope PSKoans {
Get-ChildItem -Path $KoanFolder -Recurse -Filter '*.Koans.ps1' | ForEach-Object {
$commandInfo = Get-Command -Name $_.FullName -ErrorAction SilentlyContinue

@{
File = $_
Position = $commandInfo.ScriptBlock.Attributes.Where{ $_.TypeID -match 'Koan' }.Position
}
}
}
}

It "<File> koans should be valid powershell" -TestCases $TestCases {
param($File)

Expand All @@ -19,8 +31,31 @@ Describe "Koan Assessment" {

It "<File> should include one (and only one) line feed at end of file" -TestCases $TestCases {
param($File)

$crlf = [Regex]::Match(($File | Get-Content -Raw), '(\r?(?<lf>\n))+\Z')
$crlf.Groups['lf'].Captures.Count | Should -Be 1
}

It "<File> should have a Koan position" -TestCases $TestCases {
param($File, $Position)

$Position | Should -Not -BeNullOrEmpty
$Position | Should -BeGreaterThan 0
}

It "Should not duplicate the Koan Position" {
$DuplicatePosition = $TestCases |
ForEach-Object { [PSCustomObject]$_ } |
Group-Object Position |
Where-Object Count -gt 1 |
ForEach-Object { '{0}: {1}' -f $_.Name, ($_.Group.File -join ', ') }

$DuplicatePosition | Should -BeNullOrEmpty
}

It "Should not have other PS1 files in the Koan directory" {
Get-ChildItem -Path $KoanFolder -Recurse -Filter '*.ps1' |
Where-Object BaseName -notmatch '\.Koans$' |
Should -BeNullOrEmpty
}
}

0 comments on commit 9c2c5f7

Please sign in to comment.