param(
[string]$Cargo = "cargo"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$tempRoot =
if ($env:RUNNER_TEMP) {
Join-Path $env:RUNNER_TEMP "qem-example-smoke"
} else {
Join-Path ([System.IO.Path]::GetTempPath()) ("qem-example-smoke-" + [System.Guid]::NewGuid().ToString("n"))
}
if (Test-Path $tempRoot) {
Remove-Item -LiteralPath $tempRoot -Recurse -Force
}
New-Item -ItemType Directory -Path $tempRoot | Out-Null
try {
$input = Join-Path $tempRoot "input.txt"
$typedOutput = Join-Path $tempRoot "typed-output.txt"
$frontendOutput = Join-Path $tempRoot "frontend-output.txt"
$editorOutput = Join-Path $tempRoot "editor-output.txt"
[System.IO.File]::WriteAllText(
$input,
"Hello qem demo`nsecond line`ncuttable text`nfinal line`n",
[System.Text.UTF8Encoding]::new($false)
)
& $Cargo run --quiet --example viewport --no-default-features -- $input 0 2
if ($LASTEXITCODE -ne 0) {
throw "viewport example failed"
}
& $Cargo run --quiet --example typed_editing --no-default-features -- $input $typedOutput
if ($LASTEXITCODE -ne 0) {
throw "typed_editing example failed"
}
if (!(Test-Path $typedOutput)) {
throw "typed_editing did not create the output file"
}
$typedText = Get-Content -LiteralPath $typedOutput -Raw
if ($typedText -notmatch "\[qem-demo\]") {
throw "typed_editing output does not contain the edited marker"
}
& $Cargo run --quiet --example frontend_session --features editor -- $input $frontendOutput
if ($LASTEXITCODE -ne 0) {
throw "frontend_session example failed"
}
if (!(Test-Path $frontendOutput)) {
throw "frontend_session did not create the output file"
}
$frontendText = Get-Content -LiteralPath $frontendOutput -Raw
if (!$frontendText.StartsWith("// saved by qem frontend_session example")) {
throw "frontend_session output does not contain the expected header"
}
& $Cargo run --quiet --example editor_session --features editor -- $input $editorOutput
if ($LASTEXITCODE -ne 0) {
throw "editor_session example failed"
}
if (!(Test-Path $editorOutput)) {
throw "editor_session did not create the output file"
}
$editorText = Get-Content -LiteralPath $editorOutput -Raw
if (!$editorText.StartsWith("// generated by qem example")) {
throw "editor_session output does not contain the expected header"
}
Write-Host "Qem example smoke passed."
}
finally {
if (Test-Path $tempRoot) {
Remove-Item -LiteralPath $tempRoot -Recurse -Force
}
}