os: Visual Studio 2013

environment:
  CTEST_OUTPUT_ON_FAILURE: 1
  ruby_version: 24-x64
  TargetPath: sassc/bin/sassc.exe
  matrix:
  - Compiler: msvc
    Config: Release
    Platform: Win32
  - Compiler: msvc
    Config: Debug
    Platform: Win32
  - Compiler: msvc
    Config: Release
    Platform: Win64
  - Compiler: mingw
    Build: static
  - Compiler: mingw
    Build: shared

cache:
  - C:\Ruby%ruby_version%\lib\ruby\gems
  - C:\mingw64

# Uncomment to debug hanging builds via RDP, password can be found/set under Environment-Variables in appveyor settings!
#
# init:
#   - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
#
# on_finish:
#   - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

install:
  - git clone https://github.com/sass/sassc.git
  - git clone https://github.com/sass/sass-spec.git
  - set PATH=C:\Ruby%ruby_version%\bin;%PATH%
  - ps: |
      if(!(gem which minitest 2>$nul)) { gem install minitest --no-ri --no-rdoc }
      if(!(gem which hrx 2>$nul)) { gem install hrx --no-ri --no-rdoc }
      if ($env:Compiler -eq "mingw" -AND -Not (Test-Path "C:\mingw64")) {
        # Install MinGW.
        $file = "x86_64-4.9.2-release-win32-seh-rt_v4-rev3.7z"
        wget https://bintray.com/artifact/download/drewwells/generic/$file -OutFile $file
        &7z x -oC:\ $file > $null
      }
  - set PATH=C:\mingw64\bin;%PATH%
  - set CC=gcc

build_script:
  - ps: |
      if ($env:Compiler -eq "mingw") {
        mingw32-make -j4 sassc
      } else {
        msbuild /m:4 /p:"Configuration=$env:Config;Platform=$env:Platform" sassc\win\sassc.sln
      }

      # print the branding art
      mv script/branding script/branding.ps1
      script/branding.ps1

      # print the version info
      &$env:TargetPath -v
      ruby -v

test_script:
  - ps: |
      $PRNR = $env:APPVEYOR_PULL_REQUEST_NUMBER
      if ($PRNR) {
        echo "Fetching info for PR $PRNR"
        wget https://api.github.com/repos/sass/libsass/pulls/$PRNR -OutFile pr.json
        $json = cat pr.json -Raw
        $SPEC_PR = [regex]::match($json,'sass\/sass-spec(#|\/pull\/)([0-9]+)').Groups[2].Value
        if ($SPEC_PR) {
          echo "Checkout sass spec PR $SPEC_PR"
          git -C sass-spec fetch -q -u origin pull/$SPEC_PR/head:ci-spec-pr-$SPEC_PR
          git -C sass-spec checkout -q --force ci-spec-pr-$SPEC_PR
        }
      }
      $env:TargetPath = Join-Path $pwd.Path $env:TargetPath
      If (Test-Path "$env:TargetPath") {
        ruby sass-spec/sass-spec.rb --probe-todo --impl libsass -c $env:TargetPath -s sass-spec/spec
        if(-not($?)) {
          echo "sass-spec tests failed"
          exit 1
        }
      } else {
        echo "spec runner not found (compile error?)"
        exit 1
      }
      Write-Host "Explicitly testing the case when cwd has Unicode characters: " -nonewline
      # See comments in gh-1774 for details.
      cd test/e2e/unicode-pwd/Sáss-UŢF8/
      &$env:TargetPath ./input.scss 2>&1>$null
      if(-not($?)) {
        echo "Failed!"
        exit 1
      } else {
        echo "Success!"
      }