refactor: use the new utils.ps1 script for operations
This commit is contained in:
@@ -9,23 +9,23 @@
|
||||
- multi-revert: Multiple commits reverted
|
||||
#>
|
||||
|
||||
. "$PSScriptRoot\..\..\util.ps1"
|
||||
|
||||
Write-Host "`n=== Verifying Module 06: Git Revert Solutions ===" -ForegroundColor Cyan
|
||||
|
||||
$allChecksPassed = $true
|
||||
$originalDir = Get-Location
|
||||
|
||||
$challengeRoot = "$PSScriptRoot\challenge"
|
||||
|
||||
# Check if challenge directory exists
|
||||
if (-not (Test-Path "challenge")) {
|
||||
Write-Host "[FAIL] Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
||||
if (-not (Test-Path "$challengeRoot")) {
|
||||
Write-Fail "Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Set-Location "challenge"
|
||||
|
||||
# Check if git repository exists
|
||||
if (-not (Test-Path ".git")) {
|
||||
Write-Host "[FAIL] Not a git repository. Run setup.ps1 first." -ForegroundColor Red
|
||||
Set-Location $originalDir
|
||||
if (-not (Test-Path "$challengeRoot\.git")) {
|
||||
Write-Fail "Not a git repository. Run setup.ps1 first." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -37,50 +37,50 @@ Write-Host "`n=== Scenario 1: Regular Revert ===" -ForegroundColor Cyan
|
||||
git switch regular-revert 2>&1 | Out-Null
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[FAIL] regular-revert branch not found" -ForegroundColor Red
|
||||
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-Host "[PASS] Revert commit found" -ForegroundColor Green
|
||||
Write-Pass "Revert commit found" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] No revert commit found" -ForegroundColor Red
|
||||
Write-Host "[HINT] Use: git revert <commit-hash>" -ForegroundColor Yellow
|
||||
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 "divide.py")) {
|
||||
Write-Host "[PASS] Broken divide.py successfully reverted (file removed)" -ForegroundColor Green
|
||||
if (-not (Test-Path "$challengeRoot\divide.py")) {
|
||||
Write-Pass "Broken divide.py successfully reverted (file removed)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] divide.py still exists (should be reverted)" -ForegroundColor Red
|
||||
Write-Host "[HINT] The bad commit should be reverted, removing divide.py" -ForegroundColor Yellow
|
||||
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 "calculator.py") {
|
||||
$calcContent = Get-Content "calculator.py" -Raw
|
||||
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-Host "[PASS] modulo function preserved (good commit after bad one)" -ForegroundColor Green
|
||||
Write-Pass "modulo function preserved (good commit after bad one)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] modulo function missing (should still exist)" -ForegroundColor Red
|
||||
Write-Host "[HINT] Only revert the bad commit, not the good ones after it" -ForegroundColor Yellow
|
||||
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-Host "[PASS] multiply function preserved (good commit before bad one)" -ForegroundColor Green
|
||||
Write-Pass "multiply function preserved (good commit before bad one)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] multiply function missing" -ForegroundColor Red
|
||||
Write-Fail "multiply function missing" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
} else {
|
||||
Write-Host "[FAIL] calculator.py not found" -ForegroundColor Red
|
||||
Write-Fail "calculator.py not found" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ Write-Host "`n=== Scenario 2: Multi Revert ===" -ForegroundColor Cyan
|
||||
git switch multi-revert 2>&1 | Out-Null
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "[FAIL] multi-revert branch not found" -ForegroundColor Red
|
||||
Write-Fail "multi-revert branch not found" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
} else {
|
||||
# Count revert commits
|
||||
@@ -101,56 +101,54 @@ if ($LASTEXITCODE -ne 0) {
|
||||
$revertCount = ($revertCommits | Measure-Object).Count
|
||||
|
||||
if ($revertCount -ge 2) {
|
||||
Write-Host "[PASS] Found $revertCount revert commits (expected at least 2)" -ForegroundColor Green
|
||||
Write-Pass "Found $revertCount revert commits (expected at least 2)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] Found only $revertCount revert commit(s), need at least 2" -ForegroundColor Red
|
||||
Write-Host "[HINT] Revert both bad commits: git revert <commit1> <commit2>" -ForegroundColor Yellow
|
||||
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 "sqrt.py")) {
|
||||
Write-Host "[PASS] Broken sqrt.py successfully reverted (file removed)" -ForegroundColor Green
|
||||
if (-not (Test-Path "$challengeRoot\sqrt.py")) {
|
||||
Write-Pass "Broken sqrt.py successfully reverted (file removed)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] sqrt.py still exists (should be reverted)" -ForegroundColor Red
|
||||
Write-Fail "sqrt.py still exists (should be reverted)" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
|
||||
# Check that logarithm.py is removed (reverted)
|
||||
if (-not (Test-Path "logarithm.py")) {
|
||||
Write-Host "[PASS] Broken logarithm.py successfully reverted (file removed)" -ForegroundColor Green
|
||||
if (-not (Test-Path "$challengeRoot\logarithm.py")) {
|
||||
Write-Pass "Broken logarithm.py successfully reverted (file removed)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] logarithm.py still exists (should be reverted)" -ForegroundColor Red
|
||||
Write-Fail "logarithm.py still exists (should be reverted)" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
|
||||
# Check calculator.py content
|
||||
if (Test-Path "calculator.py") {
|
||||
$calcContent = Get-Content "calculator.py" -Raw
|
||||
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-Host "[PASS] power function preserved" -ForegroundColor Green
|
||||
Write-Pass "power function preserved" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] power function missing (should still exist)" -ForegroundColor Red
|
||||
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-Host "[PASS] absolute function preserved" -ForegroundColor Green
|
||||
Write-Pass "absolute function preserved" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] absolute function missing (should still exist)" -ForegroundColor Red
|
||||
Write-Fail "absolute function missing (should still exist)" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
} else {
|
||||
Write-Host "[FAIL] calculator.py not found" -ForegroundColor Red
|
||||
Write-Fail "calculator.py not found" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
}
|
||||
|
||||
Set-Location $originalDir
|
||||
|
||||
# Final summary
|
||||
Write-Host ""
|
||||
if ($allChecksPassed) {
|
||||
|
||||
Reference in New Issue
Block a user