Skip to content

Commit

Permalink
MOre tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Oct 20, 2024
1 parent 8a429e0 commit 01308e6
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions bin/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ function Add-Packages-ExerciseImplementation($PracticeExercisesDir) {
function Test-Refactoring-Projects($PracticeExercisesDir) {
Write-Output "Testing refactoring projects"
@("tree-building", "ledger", "markdown") | ForEach-Object {
Invoke-Tests -Path "$PracticeExercisesDir/$_"
dotnet test "${PracticeExercisesDir}/${_}"
}
}

function Set-ExampleImplementation {
[CmdletBinding(SupportsShouldProcess)]
param($ExercisesDir, $ReplaceFileName)

if ($PSCmdlet.ShouldProcess("Exercise $ReplaceFileName", "replace solution with example")) {
if ($PSCmdlet.ShouldProcess("Exercise ${ReplaceFileName}", "replace solution with example")) {
Get-ChildItem -Path $ExercisesDir -Include "*.fsproj" -Recurse | ForEach-Object {
$stub = Join-Path -Path $_.Directory ($_.BaseName + ".fs")
$stub = Join-Path -Path $_.Directory ($_.BaseName + ".cs")
$example = Join-Path -Path $_.Directory ".meta" $ReplaceFileName

Move-Item -Path $example -Destination $stub -Force
Expand All @@ -86,41 +86,27 @@ function Use-ExampleImplementation {
}
}

function Test-ExerciseImplementation($Exercise, $BuildDir, $ConceptExercisesDir, $PracticeExercisesDir, $IsCI) {
function Test-ExerciseImplementation($Exercise, $BuildDir, $ConceptExercisesDir, $PracticeExercisesDir) {
Write-Output "Running tests"

if (-Not $Exercise) {
Invoke-Tests -Path $BuildDir -IsCI $IsCI
dotnet test $BuildDir
}
elseif (Test-Path "$ConceptExercisesDir/$Exercise") {
Invoke-Tests -Path "$ConceptExercisesDir/$Exercise" -IsCI $IsCI
elseif (Test-Path "${ConceptExercisesDir}/${Exercise}") {
dotnet test "${ConceptExercisesDir}/${Exercise}"
}
elseif (Test-Path "$PracticeExercisesDir/$Exercise") {
Invoke-Tests -Path "$PracticeExercisesDir/$Exercise" -IsCI $IsCI
elseif (Test-Path "${PracticeExercisesDir}/${Exercise}") {
dotnet test "${PracticeExercisesDir}/${Exercise}"
}
else {
throw "Could not find exercise '$Exercise'"
throw "Could not find exercise '${Exercise}'"
}
}

function Invoke-Tests($Path, $IsCI) {
if ($IsCI) {
Get-ChildItem -Path $Path -Include "*.fsproj" -Recurse | ForEach-Object {
& dotnet add $_.FullName package JunitXml.TestLogger -n -v 3.0.134
}
& dotnet test $Path --logger "junit;LogFilePath=results/test.xml"
}
else {
& dotnet test "$Path"
}
}


$buildDir = Join-Path $PSScriptRoot "build"
$practiceExercisesDir = Join-Path $buildDir "practice"
$conceptExercisesDir = Join-Path $buildDir "concept"
$buildDir = "${PSScriptRoot}/build"
$practiceExercisesDir = "${buildDir}/practice"
$conceptExercisesDir = "${buildDir}/concept"
$sourceDir = Resolve-Path "exercises"
$isCi = [System.Convert]::ToBoolean($env:CI)

Clean $buildDir
Copy-Exercise $sourceDir $buildDir
Expand All @@ -133,4 +119,4 @@ if (!$Exercise) {

Use-ExampleImplementation $conceptExercisesDir $practiceExercisesDir
Add-Packages-ExerciseImplementation -PracticeExercisesDir $practiceExercisesDir
Test-ExerciseImplementation -Exercise $Exercise -BuildDir $buildDir -ConceptExercisesDir $conceptExercisesDir -PracticeExercisesDir $practiceExercisesDir -IsCI $isCi
Test-ExerciseImplementation -Exercise $Exercise -BuildDir $buildDir -ConceptExercisesDir $conceptExercisesDir -PracticeExercisesDir $practiceExercisesDir

0 comments on commit 01308e6

Please sign in to comment.