#!/bin/sh

set -o errexit
set -o nounset
set -o noclobber

out=/tmp/constr-regression.$$.log

opt="-q --vanilla --no-save"

tests="
passing/AlgebraErrorDetection.R
passing/LCAlazarsfeld-rewrite.R
passing/LCAlazarsfeld.R
passing/MultivariateConstraint.R
passing/NamesReferencesErrorDetection.R
passing/RenameAndSummary.R
passing/SimpleConstraint.R
passing/StateSpaceAlg.R
passing/UnivHetModTwinAnalysis_MatrixRawOrdNIQmfFv3.R
passing/UselessConstraint.R
passing/oneLocusLikelihood.R
passing/rowAlgTest140708.R
passing/StateSpaceOsc.R
passing/SubStateSpaceOsc.R
passing/StateSpaceInputs.R
passing/AnalyticConstraintJacobians--Eq_and_Ineq.R
passing/AnalyticConstraintJacobians--PowellBenchmark.R
passing/BukinN2_regressiontest.R
passing/DogChain.R
passing/NelderMeadTest--eqConstraint.R
passing/NelderMeadTest--ineqConstraints.R
passing/PartialAnalyticDeriv.R
passing/RemoveEntriesTest.R
passing/SimpleConfidenceIntervals.R
passing/checkStandardizedLoadingsEtcetera.R
passing/dependentConstraintTest.R
passing/multinomSE.R
passing/redundantConstraintTest.R
passing/stdizedRAMpaths--UserProvidedCov.R
passing/testNumericDerivWithConstraintWarning.R
nightly/180209--defvars.R
nightly/Extreme_Multiformity_chi.R
nightly/startsTestMissing.R
"

for t in $tests; do
  echo $t
  if false; then
    R $opt -f models/$t
  else
    if ! R $opt -f models/$t > $out 2>&1; then
      if grep -q -F "Error: SKIP" $out; then
        echo "  ... skipped"
        rm -f $out
      else
        cat $out
        exit
      fi
    else
      rm -f $out
    fi
  fi
done
