ok cool,
This commit is contained in:
+106
-40
@@ -3,14 +3,21 @@
|
||||
|
||||
param(
|
||||
[string]$Package = "lda-ipjs",
|
||||
[string]$TestName = "",
|
||||
[switch]$AllPackages,
|
||||
[string]$Filter = "",
|
||||
[switch]$Exact,
|
||||
[switch]$List,
|
||||
[ValidateSet("debug", "release")]
|
||||
[string]$BuildProfile = "debug",
|
||||
[string]$password,
|
||||
[switch]$Verbose,
|
||||
[string]$RemoteTestPath = "/root/.bin/test",
|
||||
[string]$RemoteHost = "[email protected]",
|
||||
[switch]$Ignored
|
||||
[switch]$Ignored,
|
||||
[switch]$IncludeIgnored,
|
||||
[switch]$NoCapture,
|
||||
[switch]$ShowOutput,
|
||||
[int]$Threads = 0
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -19,49 +26,108 @@ $ErrorActionPreference = "Stop"
|
||||
|
||||
$password = Get-DefaultPassword $password
|
||||
|
||||
# Build tests and capture output
|
||||
Write-Host "Building tests for $Package..." -ForegroundColor Cyan
|
||||
|
||||
# Stream cargo output anc convert to text
|
||||
$cargoOutput = cargo test --no-run -p $Package --target armv7-unknown-linux-musleabihf $(if ($BuildProfile -eq "release") { "-r" }) 2>&1 |
|
||||
ForEach-Object {
|
||||
$line = if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.ToString() } else { $_ }
|
||||
if ($Verbose) {
|
||||
Write-Host $line
|
||||
function Get-WorkspacePackages {
|
||||
$metadata = cargo metadata --no-deps --format-version 1 | ConvertFrom-Json
|
||||
$workspaceMembers = [System.Collections.Generic.HashSet[string]]::new()
|
||||
foreach ($member in $metadata.workspace_members) {
|
||||
[void]$workspaceMembers.Add($member)
|
||||
}
|
||||
$line # Pass through to capture
|
||||
|
||||
@(
|
||||
$metadata.packages |
|
||||
Where-Object { $workspaceMembers.Contains($_.id) } |
|
||||
Select-Object -ExpandProperty name
|
||||
)
|
||||
}
|
||||
|
||||
# Parse test binary paths from cargo output
|
||||
$testBinaries = $cargoOutput |
|
||||
Select-String -Pattern "Executable.*\((.+)\)" |
|
||||
ForEach-Object { $_.Matches.Groups[1].Value } |
|
||||
Get-Item
|
||||
function Get-TestBinaryPaths {
|
||||
param([string[]]$CargoOutput)
|
||||
|
||||
if ($testBinaries.Count -eq 0) {
|
||||
Write-Error "No test binaries found! Exiting..."
|
||||
# Write-Host "Cargo output:" -ForegroundColor Yellow
|
||||
# $cargoOutput | ForEach-Object { Write-Host $_ }
|
||||
@(
|
||||
$CargoOutput |
|
||||
Select-String -Pattern "Executable.*\((.+)\)" |
|
||||
ForEach-Object { $_.Matches.Groups[1].Value }
|
||||
)
|
||||
}
|
||||
|
||||
function Build-RemoteExecCommand {
|
||||
param(
|
||||
[string]$RemotePath,
|
||||
[string[]]$Arguments
|
||||
)
|
||||
|
||||
$quotedPath = Quote-ShArg $RemotePath
|
||||
$quotedArgs = @($Arguments | ForEach-Object { Quote-ShArg "$_" })
|
||||
$exec = (@($quotedPath) + $quotedArgs) -join " "
|
||||
"chmod +x $quotedPath && $exec"
|
||||
}
|
||||
|
||||
$packages = if ($AllPackages) { Get-WorkspacePackages } else { @($Package) }
|
||||
$failures = New-Object System.Collections.Generic.List[string]
|
||||
|
||||
foreach ($packageName in $packages) {
|
||||
Write-Host "Building tests for $packageName..." -ForegroundColor Cyan
|
||||
|
||||
# Stream cargo output and convert to text
|
||||
$cargoOutput = cargo test --no-run -p $packageName --target armv7-unknown-linux-musleabihf $(if ($BuildProfile -eq "release") { "-r" }) 2>&1 |
|
||||
ForEach-Object {
|
||||
$line = if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.ToString() } else { $_ }
|
||||
if ($Verbose) {
|
||||
Write-Host $line
|
||||
}
|
||||
$line
|
||||
}
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
$failures.Add("$packageName (build failed)")
|
||||
Write-Warning "Build failed for $packageName"
|
||||
continue
|
||||
}
|
||||
|
||||
$testBinaryPaths = Get-TestBinaryPaths $cargoOutput
|
||||
$testBinaries = @($testBinaryPaths | Get-Item)
|
||||
|
||||
if ($testBinaries.Count -eq 0) {
|
||||
Write-Host "Skipping ${packageName}: no test executables" -ForegroundColor DarkYellow
|
||||
continue
|
||||
}
|
||||
|
||||
Write-Host "Found $($testBinaries.Count) test $($testBinaries.Count -eq 1 ? "binary" : "binaries") for $packageName" -ForegroundColor Green
|
||||
|
||||
foreach ($testBinary in $testBinaries) {
|
||||
Write-Host "`nTesting: $packageName / $($testBinary.Name)" -ForegroundColor Cyan
|
||||
|
||||
try {
|
||||
# Copy and make executable
|
||||
Invoke-Scp -Local $testBinary.FullName -Dest "${RemoteHost}:$RemoteTestPath" -Pass $password -Quiet
|
||||
|
||||
# Build test args
|
||||
$parts = @()
|
||||
if ($Filter) { $parts += $Filter }
|
||||
if ($Exact) { $parts += "--exact" }
|
||||
if ($List) { $parts += "--list" }
|
||||
if ($Ignored) { $parts += "--ignored" }
|
||||
if ($IncludeIgnored) { $parts += "--include-ignored" }
|
||||
if ($ShowOutput -or $Verbose) { $parts += "--show-output" }
|
||||
if ($NoCapture -or $Verbose) { $parts += "--nocapture" }
|
||||
if ($Threads -gt 0) { $parts += "--test-threads"; $parts += $Threads }
|
||||
$remoteCmd = Build-RemoteExecCommand -RemotePath $RemoteTestPath -Arguments $parts
|
||||
|
||||
# Run test binary (with chmod to ensure executable)
|
||||
Invoke-Ssh -Cmd $remoteCmd -Remote $RemoteHost -Pass $password
|
||||
}
|
||||
catch {
|
||||
$failures.Add("$packageName / $($testBinary.Name)")
|
||||
Write-Warning "Test binary failed: $packageName / $($testBinary.Name)"
|
||||
Write-Warning $_.Exception.Message
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($failures.Count -gt 0) {
|
||||
Write-Error ("One or more test binaries failed: {0}" -f ($failures -join ", "))
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Found $($testBinaries.Count) test $($testBinaries.Count -eq 1 ? "binary" : "binaries")" -ForegroundColor Green
|
||||
|
||||
# Run each test binary
|
||||
foreach ($testBinary in $testBinaries) {
|
||||
Write-Host "`nTesting: $($testBinary.Name)" -ForegroundColor Cyan
|
||||
|
||||
# Copy to target
|
||||
Invoke-Scp -Local $testBinary.FullName -Dest "${RemoteHost}:$RemoteTestPath" -Pass $password -Quiet
|
||||
|
||||
# Run on target
|
||||
$parts = @()
|
||||
if ($TestName) { $parts += $TestName }
|
||||
if ($Ignored) { $parts += "--ignored" }
|
||||
if ($Verbose) { $parts += "--nocapture"; $parts += "--show-output" }
|
||||
$testArgs = $parts -join " "
|
||||
|
||||
Invoke-Ssh -Cmd "chmod +x $RemoteTestPath && $RemoteTestPath $testArgs" -Remote $RemoteHost -Pass $password
|
||||
}
|
||||
|
||||
Write-Host "`nDone!" -ForegroundColor Green
|
||||
|
||||
Reference in New Issue
Block a user