2026-11-28 18:33:08 +00:00
|
|
|
<#
|
|
|
|
|
Runs the in-game test suite. RimWorld 1.7 starts headless (no window, no focus change) with its
|
|
|
|
|
own save data folder, so your mod list, saves and settings stay untouched. Needs Steam running and
|
|
|
|
|
the Harmony mod from the Workshop. Exit code: 0 all passed, 1 failures, 2 the run didn't finish.
|
|
|
|
|
|
2026-11-29 08:19:26 +00:00
|
|
|
.\Tests\run-tests.ps1 Harmony, the installed DLCs, Blax Slaves
|
|
|
|
|
.\Tests\run-tests.ps1 -Compat also the installed mods Blax Slaves has compat code for
|
2026-11-29 16:07:37 +00:00
|
|
|
.\Tests\run-tests.ps1 -NoDlc core only, no DLC (tests that need a DLC skip with "needs <DLC>")
|
|
|
|
|
.\Tests\run-tests.ps1 -Dlc Royalty,Biotech only these installed DLCs
|
2026-11-29 08:19:26 +00:00
|
|
|
.\Tests\run-tests.ps1 -NoBuild skip dotnet build
|
|
|
|
|
.\Tests\run-tests.ps1 -AllowWhileRunning run next to an open RimWorld (the test game runs at below-normal priority)
|
2026-11-28 18:33:08 +00:00
|
|
|
|
|
|
|
|
While it runs, the test mod is linked into the game's Mods folder; the link is removed afterwards.
|
2026-11-29 08:19:26 +00:00
|
|
|
Only one run at a time: a lock file in the data folder holds the running script's process id.
|
2026-11-29 16:07:37 +00:00
|
|
|
The results go to BlaxSlavesTestResults.txt in the data folder, and a copy per DLC set next to it:
|
2026-11-29 19:49:45 +00:00
|
|
|
BlaxSlavesTestResults.all.txt (every installed DLC), .nodlc.txt, or .dlc-<names>.txt. Runs with -Compat
|
|
|
|
|
write .<set>-compat.txt instead (.all-compat.txt, .nodlc-compat.txt, ...). Each copy starts with a
|
|
|
|
|
"REPO <path>" line naming the copy of the repo that was tested. The Workshop upload checks the "all" and
|
|
|
|
|
"nodlc" copies.
|
2026-11-28 18:33:08 +00:00
|
|
|
#>
|
|
|
|
|
param(
|
|
|
|
|
[string]$RimWorldDir = 'E:\SteamLibrary\steamapps\common\RimWorld',
|
|
|
|
|
[string]$DataDir = (Join-Path $env:TEMP 'BlaxSlavesTest'),
|
|
|
|
|
[switch]$Compat,
|
2026-11-29 16:07:37 +00:00
|
|
|
[switch]$NoDlc,
|
|
|
|
|
[string[]]$Dlc,
|
2026-11-28 18:33:08 +00:00
|
|
|
[switch]$NoBuild,
|
2026-11-29 08:19:26 +00:00
|
|
|
[switch]$AllowWhileRunning,
|
2026-11-28 18:33:08 +00:00
|
|
|
[int]$TimeoutSeconds = 900
|
|
|
|
|
)
|
|
|
|
|
$ErrorActionPreference = 'Stop'
|
2026-11-29 10:54:03 +00:00
|
|
|
# A wrong path (for example a switch passed as a positional value) would put the Mods junction somewhere odd.
|
|
|
|
|
if (-not (Test-Path -LiteralPath (Join-Path $RimWorldDir 'Assembly-CSharp.dll'))) { throw "No RimWorld 1.7 install at '$RimWorldDir'." }
|
2026-11-28 18:33:08 +00:00
|
|
|
$repo = Split-Path -Parent $PSScriptRoot
|
|
|
|
|
$testMod = Join-Path $PSScriptRoot 'BlaxSlavesTests'
|
|
|
|
|
$link = Join-Path $RimWorldDir 'Mods\BlaxSlavesTests'
|
|
|
|
|
$workshop = Join-Path $RimWorldDir '..\..\workshop\content\294100'
|
2026-11-29 08:19:26 +00:00
|
|
|
$lockFile = Join-Path $DataDir 'run.lock'
|
2026-11-28 18:33:08 +00:00
|
|
|
|
2026-11-29 08:19:26 +00:00
|
|
|
if ((Get-Process -Name RimWorld -ErrorAction SilentlyContinue) -and -not $AllowWhileRunning) {
|
|
|
|
|
throw 'RimWorld is running. Close it first, or pass -AllowWhileRunning.'
|
|
|
|
|
}
|
2026-11-28 18:33:08 +00:00
|
|
|
|
2026-11-29 08:19:26 +00:00
|
|
|
# One run at a time. A lock whose process is gone is stale and taken over.
|
|
|
|
|
New-Item -ItemType Directory -Force $DataDir | Out-Null
|
|
|
|
|
function Enter-Lock {
|
|
|
|
|
for ($try = 0; $try -lt 2; $try++) {
|
|
|
|
|
try {
|
|
|
|
|
$stream = [IO.File]::Open($lockFile, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::Read)
|
|
|
|
|
$bytes = [Text.Encoding]::ASCII.GetBytes([string]$PID)
|
|
|
|
|
$stream.Write($bytes, 0, $bytes.Length)
|
|
|
|
|
$stream.Close()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
catch [IO.IOException] {
|
|
|
|
|
$owner = (Get-Content -LiteralPath $lockFile -Raw -ErrorAction SilentlyContinue)
|
|
|
|
|
$ownerPid = 0
|
|
|
|
|
if ($owner -and [int]::TryParse($owner.Trim(), [ref]$ownerPid) -and $ownerPid -ne $PID -and (Get-Process -Id $ownerPid -ErrorAction SilentlyContinue)) {
|
|
|
|
|
throw "Another test run (process $ownerPid) is in progress. Lock: $lockFile"
|
|
|
|
|
}
|
|
|
|
|
Write-Warning "removing stale lock from process $owner"
|
|
|
|
|
Remove-Item -LiteralPath $lockFile -Force -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
2026-11-28 18:33:08 +00:00
|
|
|
}
|
2026-11-29 08:19:26 +00:00
|
|
|
throw "Could not take the lock $lockFile"
|
2026-11-28 18:33:08 +00:00
|
|
|
}
|
2026-11-29 08:19:26 +00:00
|
|
|
Enter-Lock
|
2026-11-28 18:33:08 +00:00
|
|
|
|
2026-11-29 08:19:26 +00:00
|
|
|
try {
|
|
|
|
|
if (-not $NoBuild) {
|
|
|
|
|
foreach ($proj in (Join-Path $repo 'Source\BlaxSlaves\BlaxSlaves.csproj'), (Join-Path $testMod 'Source\BlaxSlavesTests.csproj')) {
|
|
|
|
|
& dotnet build $proj -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir"
|
|
|
|
|
if ($LASTEXITCODE -ne 0) { throw "build failed: $proj" }
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-28 18:33:08 +00:00
|
|
|
|
2026-11-29 08:19:26 +00:00
|
|
|
# packageId (lower case) -> About.xml, for every installed local and Workshop mod
|
|
|
|
|
$installed = @{}
|
|
|
|
|
foreach ($about in @(Get-ChildItem (Join-Path $RimWorldDir 'Mods\*\About\About.xml') -ErrorAction SilentlyContinue) +
|
|
|
|
|
@(Get-ChildItem (Join-Path $workshop '*\About\About.xml') -ErrorAction SilentlyContinue)) {
|
|
|
|
|
$x = [xml](Get-Content -LiteralPath $about.FullName -Raw -Encoding UTF8)
|
|
|
|
|
if ($x.ModMetaData.packageId) { $installed[$x.ModMetaData.packageId.Trim().ToLower()] = $x }
|
2026-11-28 18:33:08 +00:00
|
|
|
}
|
2026-11-29 08:19:26 +00:00
|
|
|
function Add-WithDependencies([string]$id, [System.Collections.ArrayList]$list) {
|
|
|
|
|
$id = $id.ToLower()
|
|
|
|
|
if ($list -contains $id -or $id -like 'ludeon.*') { return }
|
|
|
|
|
$x = $installed[$id]
|
|
|
|
|
if (-not $x) { Write-Warning "not installed, skipped: $id"; return }
|
|
|
|
|
foreach ($dep in @($x.ModMetaData.modDependencies.li)) { if ($dep.packageId) { Add-WithDependencies $dep.packageId $list } }
|
|
|
|
|
[void]$list.Add($id)
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-29 16:07:37 +00:00
|
|
|
# Every installed DLC is listed as known, so the game does not switch on a left-out DLC as "new".
|
|
|
|
|
$installedDlcs = @(@('Royalty', 'Ideology', 'Biotech', 'Anomaly', 'Odyssey') | Where-Object { Test-Path (Join-Path $RimWorldDir "Data\$_") })
|
|
|
|
|
if ($NoDlc) { $loadDlcs = @() }
|
|
|
|
|
elseif ($Dlc) {
|
|
|
|
|
$wanted = @($Dlc | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ })
|
|
|
|
|
foreach ($w in $wanted) { if ($installedDlcs -notcontains $w) { Write-Warning "DLC not installed or unknown, skipped: $w" } }
|
|
|
|
|
$loadDlcs = @($installedDlcs | Where-Object { $wanted -contains $_ })
|
|
|
|
|
}
|
|
|
|
|
else { $loadDlcs = @($installedDlcs) }
|
2026-11-29 08:19:26 +00:00
|
|
|
$mods = New-Object System.Collections.ArrayList
|
2026-11-29 16:07:37 +00:00
|
|
|
$expansions = @($installedDlcs | ForEach-Object { 'ludeon.rimworld.' + $_.ToLower() })
|
2026-11-29 08:19:26 +00:00
|
|
|
[void]$mods.Add('brrainz.harmony')
|
|
|
|
|
[void]$mods.Add('ludeon.rimworld')
|
2026-11-29 16:07:37 +00:00
|
|
|
foreach ($d in $loadDlcs) { [void]$mods.Add('ludeon.rimworld.' + $d.ToLower()) }
|
|
|
|
|
Write-Host ("DLCs: " + $(if ($loadDlcs.Count) { $loadDlcs -join ', ' } else { 'none' }))
|
|
|
|
|
# Name of this DLC set for the per-set copy of the results.
|
|
|
|
|
$dlcSet = if ($loadDlcs.Count -eq 0) { 'nodlc' } elseif ($loadDlcs.Count -eq $installedDlcs.Count) { 'all' } else { 'dlc-' + ($loadDlcs -join '-').ToLower() }
|
2026-11-29 19:49:45 +00:00
|
|
|
# Other mods change what runs and what skips, so their runs never stand in for the plain ones.
|
|
|
|
|
if ($Compat) { $dlcSet += '-compat' }
|
2026-11-29 16:07:37 +00:00
|
|
|
$setResults = Join-Path $DataDir "BlaxSlavesTestResults.$dlcSet.txt"
|
2026-11-29 08:19:26 +00:00
|
|
|
if ($Compat) {
|
|
|
|
|
foreach ($id in 'unlimitedhugs.hugslib', 'orion.hospitality', 'smuffle.harvestorganspostmortem',
|
|
|
|
|
'mersid.wce2updated.core', 'mlie.syrmoreslaves', 'bblkepling.everybodybuysslaves',
|
|
|
|
|
'rhajiit.tradepurchasemode') {
|
|
|
|
|
Add-WithDependencies $id $mods
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[void]$mods.Add('blax.slaves')
|
|
|
|
|
[void]$mods.Add('blax.slaves.tests')
|
2026-11-28 18:33:08 +00:00
|
|
|
|
2026-11-29 08:19:26 +00:00
|
|
|
# fresh test data folder: mod list only, no old save, results or mod settings
|
|
|
|
|
New-Item -ItemType Directory -Force (Join-Path $DataDir 'Config') | Out-Null
|
2026-11-29 16:07:37 +00:00
|
|
|
Remove-Item -Force -ErrorAction SilentlyContinue (Join-Path $DataDir 'Saves\BlaxSlavesTest.rws'), (Join-Path $DataDir 'BlaxSlavesTestResults.txt'), $setResults, (Join-Path $DataDir 'Config\Mod_blax.slaves_*.xml')
|
2026-11-29 08:19:26 +00:00
|
|
|
$li = { param($ids) ($ids | ForEach-Object { " <li>$_</li>" }) -join "`n" }
|
|
|
|
|
$modsConfig = "<?xml version=`"1.0`" encoding=`"utf-8`"?>`n<ModsConfigData>`n <version>1.7</version>`n <activeMods>`n" +
|
|
|
|
|
(& $li $mods) + "`n </activeMods>`n <knownExpansions>`n" + (& $li $expansions) + "`n </knownExpansions>`n</ModsConfigData>`n"
|
|
|
|
|
[IO.File]::WriteAllText((Join-Path $DataDir 'Config\ModsConfig.xml'), $modsConfig)
|
|
|
|
|
Write-Host ("Mods: " + ($mods -join ', '))
|
2026-11-28 18:33:08 +00:00
|
|
|
|
2026-11-29 08:19:26 +00:00
|
|
|
$createdLink = $false
|
|
|
|
|
try {
|
|
|
|
|
if (-not (Test-Path $link)) {
|
|
|
|
|
New-Item -ItemType Junction -Path $link -Target $testMod | Out-Null
|
|
|
|
|
$createdLink = $true
|
|
|
|
|
}
|
|
|
|
|
$gameArgs = "-headless -quicktest -blaxslavestests -NoFileLog -NoCrashDialog `"-savedatafolder=$DataDir`""
|
|
|
|
|
$sw = [Diagnostics.Stopwatch]::StartNew()
|
|
|
|
|
$p = Start-Process -FilePath (Join-Path $RimWorldDir 'RimWorld.exe') -WorkingDirectory $RimWorldDir -ArgumentList $gameArgs `
|
|
|
|
|
-RedirectStandardOutput (Join-Path $DataDir 'game.log') -RedirectStandardError (Join-Path $DataDir 'game.err.log') `
|
|
|
|
|
-WindowStyle Hidden -PassThru
|
|
|
|
|
if ($AllowWhileRunning) {
|
|
|
|
|
try { $p.PriorityClass = [Diagnostics.ProcessPriorityClass]::BelowNormal } catch { Write-Warning "could not lower the test game's priority: $_" }
|
|
|
|
|
}
|
|
|
|
|
if (-not $p.WaitForExit($TimeoutSeconds * 1000)) {
|
|
|
|
|
$p.Kill()
|
|
|
|
|
Write-Warning "timed out after $TimeoutSeconds s, test game (process $($p.Id)) killed"
|
|
|
|
|
}
|
|
|
|
|
Write-Host ("Game ran {0:N0} s. Log: {1}" -f $sw.Elapsed.TotalSeconds, (Join-Path $DataDir 'game.log'))
|
2026-11-28 18:33:08 +00:00
|
|
|
}
|
2026-11-29 08:19:26 +00:00
|
|
|
finally {
|
|
|
|
|
if ($createdLink -and (Test-Path $link)) { cmd /c rmdir "$link" | Out-Null }
|
2026-11-28 18:33:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally {
|
2026-11-29 08:19:26 +00:00
|
|
|
Remove-Item -LiteralPath $lockFile -Force -ErrorAction SilentlyContinue
|
2026-11-28 18:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$results = Join-Path $DataDir 'BlaxSlavesTestResults.txt'
|
|
|
|
|
if (-not (Test-Path $results)) { Write-Host 'No results file: the suite never started. See game.log.'; exit 2 }
|
2026-11-29 19:49:45 +00:00
|
|
|
# The per-set copy names the tested copy of the repo, so the Workshop upload never takes another copy's run.
|
|
|
|
|
[IO.File]::WriteAllLines($setResults, [string[]](@("REPO $repo") + @(Get-Content -LiteralPath $results -Encoding UTF8)), (New-Object Text.UTF8Encoding $false))
|
2026-11-28 18:33:08 +00:00
|
|
|
$lines = Get-Content -LiteralPath $results -Encoding UTF8
|
|
|
|
|
$lines | ForEach-Object { Write-Host $_ }
|
|
|
|
|
if (-not ($lines -match '^END$')) { Write-Host 'The run did not finish.'; exit 2 }
|
|
|
|
|
if ($lines -match '^FAIL ') { exit 1 }
|
|
|
|
|
exit 0
|