# httpd mode: the server runs the site with httpd class from etc/auto.p, see site/config.p # Windows version of run_tests.sh, tests with curl (*.curl) are skipped, so the output differs from ok.log for them # run as: powershell -ExecutionPolicy Bypass -File run_tests.ps1 param([string]$Parser = "$PSScriptRoot\..\..\src\targets\cgi\Release\parser3.exe") $Port = 8100 $Latin1 = [Text.Encoding]::GetEncoding(28591) # bytes <-> chars as is function Send-File($file) { $client = New-Object Net.Sockets.TcpClient('127.0.0.1', $Port) $client.ReceiveTimeout = 10000 $stream = $client.GetStream() $response = New-Object IO.MemoryStream $buffer = New-Object byte[] 4096 try { $request = [IO.File]::ReadAllBytes($file) $stream.Write($request, 0, $request.Length) while (($n = $stream.Read($buffer, 0, $buffer.Length)) -gt 0) { $response.Write($buffer, 0, $n) } } catch [IO.IOException] { } # connection reset or timeout, the received part is kept $client.Close() $Latin1.GetString($response.ToArray()) } # etc/auto.p is generated by configure from auto.p.in, which is not run under Windows $auto = "$PSScriptRoot\..\..\etc\auto.p" $generated = -not (Test-Path $auto) $server = $null try { if ($generated) { $text = [IO.File]::ReadAllText("$auto.in", $Latin1) -replace '@dll_extension@', 'dll' -replace '@\w+@', '.' [IO.File]::WriteAllText($auto, $text, $Latin1) } $server = Start-Process $Parser -ArgumentList '-f', 'config.p', '-p', $Port -WorkingDirectory "$PSScriptRoot\site" -WindowStyle Hidden -PassThru # wait for the server listens for ($i = 0; $i -lt 50; $i++) { try { (New-Object Net.Sockets.TcpClient('127.0.0.1', $Port)).Close(); break } catch { Start-Sleep -Milliseconds 100 } } # the dates and the version of the server differ from run to run $log = New-Object Text.StringBuilder foreach ($f in Get-ChildItem "$PSScriptRoot\*" -Include '???.txt', '???.curl' -File | Sort-Object Name) { if ($f.Extension -eq '.curl') { Write-Host "skipped $($f.Name)"; continue } [void]$log.Append("running test $($f.Name)`n") [void]$log.Append((Send-File $f.FullName)) [void]$log.Append("`n=============`n") } $text = $log.ToString() -replace '(?m)^(Date|Last-Modified): .* GMT', '$1: DATE GMT' -replace '(?m)^Server: Parser3\.[\x20-\x7E]*', 'Server: Parser3.X.X ...' [IO.File]::WriteAllBytes("$PSScriptRoot\tests.log", $Latin1.GetBytes($text)) } finally { if ($server) { Stop-Process -Id $server.Id -Force -ErrorAction SilentlyContinue $server.WaitForExit() } if ($generated) { Remove-Item $auto -ErrorAction SilentlyContinue } } Remove-Item "$PSScriptRoot\site\parser3.log" -ErrorAction SilentlyContinue $diff = "$PSScriptRoot\..\..\..\win32\tools\cygwin\bin\diff.exe" if (-not (Test-Path $diff)) { $diff = 'diff' } Push-Location $PSScriptRoot & $diff -u ok.log tests.log $result = $LASTEXITCODE Pop-Location exit $result