# Copyright 2013 Samsung Information Systems America, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Author: Koushik Sen


# Assumes that JALANGI_HOME is different from project home.
# Assumes that the script is run from the project home.


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export JALANGI_HOME=$DIR/..
cd jalangi_tmp
pwd

export CMD='cover run '

cp ../.coverignore .
rm -rf .coverage_data
rm inputs.js
touch inputs.js

#echo "***************** Running ($1.js:1:1) on (jalangi_tmp/inputs.js:1:1) ********************"
$CMD ../$1.js &>/dev/null

for i in jalangi_inputs*
do
#    echo "***************** Running ($1.js:1:1) on (jalangi_tmp/$i:1:1) ********************"
    cp $i inputs.js
    $CMD ../$1.js &>/dev/null
done

echo "***************** Running ($1.js:1:1) on (jalangi_tmp/inputs.js:1:1) ********************"
node ../$1.js

for i in jalangi_inputs*
do
    echo "***************** Running ($1.js:1:1) on (jalangi_tmp/$i:1:1) ********************"
    cp $i inputs.js
    node ../$1.js
done

    echo "***************** Done testing ********************"
    sleep 2
    cover combine
    cover report html
    cp cover_html/index.html ../jalangi/out/out.html
    cp cover_html/*.* ../jalangi/out/

