#! /bin/sh
#
# How I run the sass-spec checker for rsass.
#
# Default run:
#     ./check-spec
# Just show which "basic" tests are still failing:
#     ./check-spec basic
# Generate stats to update lib.rs docs and readme:
#     ./check-spec stats
#
cd `dirname $0`
cargo build --release

if [ -d sass-spec ]; then
   cd sass-spec
   git up
else
   git clone https://github.com/sass/sass-spec.git
   cd sass-spec
fi

cat > spec/output_styles/options.yml <<EOF
---
:start_version: '3.4'
:only_on:
- libsass
- rsass
EOF

cat > spec/output_styles/compact/options.yml <<EOF
---
:output_style: :compact
:ignore_for:
- rsass
EOF

cat > spec/output_styles/nested/options.yml <<EOF
---
:output_style: :nested
:ignore_for:
- rsass
EOF

case "$1" in
    "")
        LC_ALL=C ./sass-spec.rb -c ../target/release/rsass --impl rsass -V 4.0 spec
        ;;
    "impersonate")
        LC_ALL=C ./sass-spec.rb -c ../target/release/rsass --impl libsass -V 4.0 spec
        ;;
    "basic")
        LC_ALL=C ./sass-spec.rb -c ../target/release/rsass --impl rsass -V 4.0 spec/basic \
            |  grep ^SassSpec:: | sed -e 's#.*test__##' -e 's# .*##' | sort
        ;;
    "scss")
        LC_ALL=C ./sass-spec.rb -c ../target/release/rsass --impl rsass -V 4.0 spec/scss
	;;
    "stats")
        LC_ALL=C ./sass-spec.rb -c ../target/release/rsass --impl rsass -V 4.0 spec \
            | rg --no-line-number '^([0-9]+) runs, ([0-9]+) assertions.*' \
                 --replace 'Progress: ![$2](http://progressed.io/bar/$2?scale=$1&suffix=+) of $1 tests passed'
        LC_ALL=C ./sass-spec.rb -c ../target/release/rsass --impl libsass -V 4.0 spec \
            | rg --no-line-number '^([0-9]+) runs, ([0-9]+) assertions.*' \
                 --replace '(or $2 of $1 when claiming to be libsass).'
        ;;
esac
