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

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

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

log.level $level




create.result 0 "$0"
expect 0 "$0" "result: $RESULT"

file="bash"
create.result 0 "$(which $file)"
expect 0 "$(which bash)" "result: $RESULT"

file="$OOSH_DIR/test/test.absolute.path"
result_path="${file#$OOSH_DIR/}"
create.result 0 "$result_path"
expect 0 "test/test.absolute.path" "result: $RESULT"

file="test.absolute.path"
result_path=$(dirname ${file#./})
create.result 0 "${result_path:-"has a path"}"
expect 0 "." "result: $RESULT"

# Get the canonical test directory path (fully resolved through all symlinks)
CANONICAL_TEST_DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")

file="${BASH_SOURCE[0]}"
result_path=$(dirname ${file#./})
create.result 0 "${result_path:-"has a path"}"
# Normalize RESULT for comparison (resolve symlinks)
RESULT=$(readlink -f "$RESULT" 2>/dev/null || echo "$RESULT")
expect 0 "$CANONICAL_TEST_DIR" "canonicalized path comparison"

test.case - "this.absolutePath $file" \
   this.absolutePath $file
# Normalize RESULT for comparison
RESULT=$(readlink -f "$RESULT" 2>/dev/null || echo "$RESULT")
expect 0 "$CANONICAL_TEST_DIR" "this.absolutePath on BASH_SOURCE"

file="$OOSH_DIR/test/test.absolute.path"
test.case - "this.absolutePath $file" \
   this.absolutePath $file
RESULT=$(readlink -f "$RESULT" 2>/dev/null || echo "$RESULT")
expect 0 "$CANONICAL_TEST_DIR" "this.absolutePath on relative path"


file="$OOSH_DIR/test/test.data/once"
test.case - "this.absolutePath $file" \
   this.absolutePath $file
# Expect the test.data directory path (canonicalized)
CANONICAL_DATA_DIR=$(readlink -f "$CANONICAL_TEST_DIR/test.data" 2>/dev/null || echo "$CANONICAL_TEST_DIR/test.data")
RESULT=$(readlink -f "$RESULT" 2>/dev/null || echo "$RESULT")
expect 0 "$CANONICAL_DATA_DIR" "this.absolutePath on test.data"

test.suite.save.results