image: Visual Studio 2019

configuration:
  - Release

platform:
  - x64

build:
  project: Project\MSVC2019\RAWcooked.sln
  verbosity: quiet

before_test:
- ps: |
    git clone https://github.com/MediaArea/RAWCooked-RegressionTestingFiles-Light.git Project/GNU/CLI/test/TestingFiles
    Invoke-WebRequest https://www.mediaarea.net/download/snapshots/binary/ffmpeg/latest/FFmpeg_Bin_Latest_Windows_Static_x64.zip -OutFile FFmpeg_Bin_Latest_Windows_Static_x64.zip
    Expand-Archive FFmpeg_Bin_Latest_Windows_Static_x64.zip -DestinationPath .
    Copy-Item bin/ffmpeg.exe -Destination Project/GNU/CLI/ffmpeg
    Copy-Item bin/ffmpeg.exe -Destination Project/GNU/CLI/ffmpeg.exe
    Copy-Item Project/MSVC2019/x64/Release/RAWcooked.exe -Destination Project/GNU/CLI/rawcooked

test_script:
- ps: |
    $fail = false

    function Run-Test {
        $name = $args[0]

        Write-Host "Running test: $name"

        Add-AppveyorTest -Name $name -Framework custom -FileName $name.sh -Outcome Running

        $measure = Measure-Command { Invoke-Expression "wsl test/`$name.sh ; `$result = `$?" -OutVariable output -ErrorVariable errors }

        Write-Host "StdOut:"
        Write-Host ($output | Out-String)

        Write-Host "StdErr:"
        Write-Host ($errors | Out-String)

        if ($result) {
            Update-AppveyorTest -Name $name -Framework custom -FileName $name.sh -Duration $measure.TotalMilliseconds -StdOut ($output  | Out-String) -StdErr ($errors | Out-String) -Outcome Passed
        }
        else {
            Update-AppveyorTest -Name $name -Framework custom -FileName $name.sh -Duration $measure.TotalMilliseconds -StdOut ($output  | Out-String) -StdErr ($errors | Out-String) -Outcome Failed
            Set-Variable -scope Script -Name "fail" -Value true
        }

        return $result
    }

    Set-Location Project/GNU/CLI
    $env:Path += ";$(Get-Location)"

    Run-Test test1
    Run-Test test1b
    Run-Test test2
    Run-Test test3
    Run-Test pcm
    Run-Test paddingbits
    Run-Test version
    Run-Test notfound
    Run-Test check
    Run-Test legacy
    Run-Test multiple
    Run-Test gaps
    Run-Test framerate
    Run-Test increasingdigitcount

    if ($fail -eq $true) {
        Exit $fail
    }

