#!/usr/bin/env bash
#clear
#export PS4='\e[90m+${LINENO} in ${#BASH_SOURCE[@]}>${FUNCNAME[0]}:${BASH_SOURCE[@]##*/} \e[0m'
#set -x

level=$1
if [ -z "$level" ]; then
  level=1
else 
  # remove the level parameter
  shift
fi
echo "starting: ${BASH_SOURCE[@]##*/} <LOG_LEVEL=$1>"

#echo "sourcing init"
source this
source test.suite

log.level $level

cd ~

check message ".bashrc exists" file .bashrc exists
RETURN_VALUE=$?
expect 0 "*" "checking .bashrc exists"

check file .bashrc exists
RETURN_VALUE=$?
expect 0 "*" "checking .bashrc exists without message"

expect.error 1
check message ".bashrc not exists" file .bashrc not exists
RETURN_VALUE=$?
expect 1 "*" ".bashrc exists therefore test check failed with warning"

expect.error 1
check file .bashrc not exists
RETURN_VALUE=$?
expect 1 "*" ".bashrc exists therefore test check failed without warning"

expect.error 1
check file config not exists
RETURN_VALUE=$?
expect 1 "*" "fails because file config is a directory"

expect.error 1
check file config not exists fix error.log "you will not see this otherwise check tried to fix this error"
RETURN_VALUE=$?
expect 1 "*" "fails because file config is a directory and does not try to fix it"

expect.error 0
check dir config exists fix error.log "you will not see this"
RETURN_VALUE=$?
expect 0 "*" "dir config exists"


expect.error 1
check dir .bashrc exists fix error.log "you will not see this"
RETURN_VALUE=$?
expect 1 "*" "dir .bashrc exists fails because .bashrc is a file and does not fix it"

# expect.error 1
check dir cool exists fix important.log "dir cool does not exist as expected"
RETURN_VALUE=$?
expect 0 "*" "dir cool not exists and therefore it fixes by important log"


expect.error 1
check message "This is a warning because dir cool does not exist" dir cool exists 
RETURN_VALUE=$?
expect 1 "*" "dir cool not exists without fixing it"




check message "this breaks completly because in check.message: this.fuctionExists checks the first word this..." dir cool exists fix important.log "fixed, does not fail anymore"
RETURN_VALUE=$?
expect 0 "*" "dir cool not exists but fixing it"


test.suite.save.results
# source $OOSH_DIR/config 
# config.save testresult TEST_SUITE
# check file $CONFIG_PATH/testresult.env exists;
# expect 0 "*" "$CONFIG_PATH/testresult.env exists"

#echo -e "\e[1;32m$TEST_SUITE_SUCCESS_COUNTER\e[0m / $TEST_SUITE_EXPECT_COUNTER expects on $TEST_SUITE_TEST_COUNTER Test Cases"


# test.case - "loop list PATH silent" \
#    loop list PATH silent
# expect 0 "*" 

# source loop

# test.case - "reverse test.wo-da.de" \
#    loop.this "test.wo-da.de" . reverse silent
# expect 0 "de.wo-da.test." 

# test.case - "convert de.wo-da.test to path" \
#    loop.this $RESULT . r / silent
# expect 0 "de/wo-da/test"

# test.case - "convert some host to scenario" \
#    loop.this somehost . add docker and add local and reverse silent and r / silent
# expect 0 "local/docker/somehost"
# # fails....strange because
# #  loop localhost . add local and add host and reverse silent and r /
# # works correctly

# test.case - "convert some host to scenario" \
#    loop somehost . add docker and add local and reverse silent and r / pipe
# expect 0 "local/docker/somehost"


# test.case - "convert some host to scenario" \
#    loop.this "somehost.docker.local" . reverse - and r / pipe
# expect 0 "local/docker/somehost"



# expect 0 "test.case - 'complete: config list' \
#   \"RESULT=\"\$(once.completion.discover 'config list')\"\"" \
#   ". config.list config list" \
#   "message $RESULT"

# test.case - "use sourced mycmd and call feature3 directly" \
#   mycmd.feature3 hello world
