Annotation of parser3/tests/httpd/run_tests.ps1, revision 1.1

1.1     ! moko        1: # httpd mode: the server runs the site with httpd class from etc/auto.p, see site/config.p
        !             2: # Windows version of run_tests.sh, tests with curl (*.curl) are skipped, so the output differs from ok.log for them
        !             3: # run as: powershell -ExecutionPolicy Bypass -File run_tests.ps1
        !             4: 
        !             5: param([string]$Parser = "$PSScriptRoot\..\..\src\targets\cgi\Release\parser3.exe")
        !             6: 
        !             7: $Port = 8100
        !             8: $Latin1 = [Text.Encoding]::GetEncoding(28591) # bytes <-> chars as is
        !             9: 
        !            10: function Send-File($file) {
        !            11:        $client = New-Object Net.Sockets.TcpClient('127.0.0.1', $Port)
        !            12:        $client.ReceiveTimeout = 10000
        !            13:        $stream = $client.GetStream()
        !            14:        $response = New-Object IO.MemoryStream
        !            15:        $buffer = New-Object byte[] 4096
        !            16:        try {
        !            17:                $request = [IO.File]::ReadAllBytes($file)
        !            18:                $stream.Write($request, 0, $request.Length)
        !            19:                while (($n = $stream.Read($buffer, 0, $buffer.Length)) -gt 0) { $response.Write($buffer, 0, $n) }
        !            20:        } catch [IO.IOException] { } # connection reset or timeout, the received part is kept
        !            21:        $client.Close()
        !            22:        $Latin1.GetString($response.ToArray())
        !            23: }
        !            24: 
        !            25: # etc/auto.p is generated by configure from auto.p.in, which is not run under Windows
        !            26: $auto = "$PSScriptRoot\..\..\etc\auto.p"
        !            27: $generated = -not (Test-Path $auto)
        !            28: $server = $null
        !            29: try {
        !            30:        if ($generated) {
        !            31:                $text = [IO.File]::ReadAllText("$auto.in", $Latin1) -replace '@dll_extension@', 'dll' -replace '@\w+@', '.'
        !            32:                [IO.File]::WriteAllText($auto, $text, $Latin1)
        !            33:        }
        !            34: 
        !            35:        $server = Start-Process $Parser -ArgumentList '-f', 'config.p', '-p', $Port -WorkingDirectory "$PSScriptRoot\site" -WindowStyle Hidden -PassThru
        !            36: 
        !            37:        # wait for the server listens
        !            38:        for ($i = 0; $i -lt 50; $i++) {
        !            39:                try { (New-Object Net.Sockets.TcpClient('127.0.0.1', $Port)).Close(); break } catch { Start-Sleep -Milliseconds 100 }
        !            40:        }
        !            41: 
        !            42:        # the dates and the version of the server differ from run to run
        !            43:        $log = New-Object Text.StringBuilder
        !            44:        foreach ($f in Get-ChildItem "$PSScriptRoot\*" -Include '???.txt', '???.curl' -File | Sort-Object Name) {
        !            45:                if ($f.Extension -eq '.curl') { Write-Host "skipped $($f.Name)"; continue }
        !            46:                [void]$log.Append("running test $($f.Name)`n")
        !            47:                [void]$log.Append((Send-File $f.FullName))
        !            48:                [void]$log.Append("`n=============`n")
        !            49:        }
        !            50:        $text = $log.ToString() -replace '(?m)^(Date|Last-Modified): .* GMT', '$1: DATE GMT' -replace '(?m)^Server: Parser3\.[\x20-\x7E]*', 'Server: Parser3.X.X ...'
        !            51:        [IO.File]::WriteAllBytes("$PSScriptRoot\tests.log", $Latin1.GetBytes($text))
        !            52: } finally {
        !            53:        if ($server) {
        !            54:                Stop-Process -Id $server.Id -Force -ErrorAction SilentlyContinue
        !            55:                $server.WaitForExit()
        !            56:        }
        !            57:        if ($generated) { Remove-Item $auto -ErrorAction SilentlyContinue }
        !            58: }
        !            59: 
        !            60: Remove-Item "$PSScriptRoot\site\parser3.log" -ErrorAction SilentlyContinue
        !            61: $diff = "$PSScriptRoot\..\..\..\win32\tools\cygwin\bin\diff.exe"
        !            62: if (-not (Test-Path $diff)) { $diff = 'diff' }
        !            63: Push-Location $PSScriptRoot
        !            64: & $diff -u ok.log tests.log
        !            65: $result = $LASTEXITCODE
        !            66: Pop-Location
        !            67: exit $result

E-mail: