Files
2026-01-21 10:51:59 +01:00

172 lines
6.8 KiB
PowerShell

#!/usr/bin/env pwsh
<#
.SYNOPSIS
Verifies the Module 06 challenge solutions.
.DESCRIPTION
Checks that both revert scenarios have been completed correctly:
- regular-revert: Single commit reverted
- multi-revert: Multiple commits reverted
#>
. "$PSScriptRoot\..\..\util.ps1"
Write-Host "`n=== Verifying Module 06: Git Revert Solutions ===" -ForegroundColor Cyan
$allChecksPassed = $true
$challengeRoot = "$PSScriptRoot\challenge"
# Check if challenge directory exists
if (-not (Test-Path "$challengeRoot")) {
Write-Fail "Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
exit 1
}
# Check if git repository exists
if (-not (Test-Path "$challengeRoot\.git")) {
Write-Fail "Not a git repository. Run setup.ps1 first." -ForegroundColor Red
exit 1
}
# ============================================================================
# SCENARIO 1: Regular Revert Verification
# ============================================================================
Write-Host "`n=== Scenario 1: Regular Revert ===" -ForegroundColor Cyan
git switch regular-revert 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Fail "regular-revert branch not found" -ForegroundColor Red
$allChecksPassed = $false
} else {
# Check that a revert commit exists
$revertCommit = git log --oneline --grep="Revert" 2>$null
if ($revertCommit) {
Write-Pass "Revert commit found" -ForegroundColor Green
} else {
Write-Fail "No revert commit found" -ForegroundColor Red
Write-Hint "Use: git revert <commit-hash>" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check that divide.py is removed (was reverted)
if (-not (Test-Path "$challengeRoot\divide.py")) {
Write-Pass "Broken divide.py successfully reverted (file removed)" -ForegroundColor Green
} else {
Write-Fail "divide.py still exists (should be reverted)" -ForegroundColor Red
Write-Hint "The bad commit should be reverted, removing divide.py" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check that calculator.py exists and has correct content
if (Test-Path "$challengeRoot\calculator.py") {
$calcContent = Get-Content "$challengeRoot\calculator.py" -Raw
# Check that modulo function still exists (should be preserved)
if ($calcContent -match "def modulo") {
Write-Pass "modulo function preserved (good commit after bad one)" -ForegroundColor Green
} else {
Write-Fail "modulo function missing (should still exist)" -ForegroundColor Red
Write-Hint "Only revert the bad commit, not the good ones after it" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check that multiply function exists (should be preserved)
if ($calcContent -match "def multiply") {
Write-Pass "multiply function preserved (good commit before bad one)" -ForegroundColor Green
} else {
Write-Fail "multiply function missing" -ForegroundColor Red
$allChecksPassed = $false
}
} else {
Write-Fail "calculator.py not found" -ForegroundColor Red
$allChecksPassed = $false
}
}
# ============================================================================
# SCENARIO 2: Multi Revert Verification
# ============================================================================
Write-Host "`n=== Scenario 2: Multi Revert ===" -ForegroundColor Cyan
git switch multi-revert 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Fail "multi-revert branch not found" -ForegroundColor Red
$allChecksPassed = $false
} else {
# Count revert commits
$revertCommits = git log --oneline --grep="Revert" 2>$null
$revertCount = ($revertCommits | Measure-Object).Count
if ($revertCount -ge 2) {
Write-Pass "Found $revertCount revert commits (expected at least 2)" -ForegroundColor Green
} else {
Write-Fail "Found only $revertCount revert commit(s), need at least 2" -ForegroundColor Red
Write-Hint "Revert both bad commits: git revert <commit1> <commit2>" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check that sqrt.py is removed (reverted)
if (-not (Test-Path "$challengeRoot\sqrt.py")) {
Write-Pass "Broken sqrt.py successfully reverted (file removed)" -ForegroundColor Green
} else {
Write-Fail "sqrt.py still exists (should be reverted)" -ForegroundColor Red
$allChecksPassed = $false
}
# Check that logarithm.py is removed (reverted)
if (-not (Test-Path "$challengeRoot\logarithm.py")) {
Write-Pass "Broken logarithm.py successfully reverted (file removed)" -ForegroundColor Green
} else {
Write-Fail "logarithm.py still exists (should be reverted)" -ForegroundColor Red
$allChecksPassed = $false
}
# Check calculator.py content
if (Test-Path "$challengeRoot\calculator.py") {
$calcContent = Get-Content "$challengeRoot\calculator.py" -Raw
# Check that power function still exists (good commit before bad ones)
if ($calcContent -match "def power") {
Write-Pass "power function preserved" -ForegroundColor Green
} else {
Write-Fail "power function missing (should still exist)" -ForegroundColor Red
$allChecksPassed = $false
}
# Check that absolute function still exists (good commit after bad ones)
if ($calcContent -match "def absolute") {
Write-Pass "absolute function preserved" -ForegroundColor Green
} else {
Write-Fail "absolute function missing (should still exist)" -ForegroundColor Red
$allChecksPassed = $false
}
} else {
Write-Fail "calculator.py not found" -ForegroundColor Red
$allChecksPassed = $false
}
}
# Final summary
Write-Host ""
if ($allChecksPassed) {
Write-Host "=========================================" -ForegroundColor Green
Write-Host " CONGRATULATIONS! ALL SCENARIOS PASSED!" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Green
Write-Host "`nYou've mastered git revert!" -ForegroundColor Cyan
Write-Host "You now understand:" -ForegroundColor Cyan
Write-Host " ✓ Reverting commits safely without erasing history" -ForegroundColor White
Write-Host " ✓ Reverting multiple commits at once" -ForegroundColor White
Write-Host " ✓ Preserving all other commits while undoing specific changes" -ForegroundColor White
Write-Host "`nReady for Module 07: Git Reset!" -ForegroundColor Green
Write-Host ""
exit 0
} else {
Write-Host "[SUMMARY] Some checks failed. Review the hints above and try again." -ForegroundColor Red
Write-Host "[INFO] You can run this verification script as many times as needed." -ForegroundColor Yellow
Write-Host ""
exit 1
}