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

test.suite.level()
{
  level=$1
  case $1 in
      ''|*[!0-9]*) 
        level=$3
        ;;
      *) echo test.suite level=$level ;;
  esac
  if [ -z "$level" ]; then
    level=$LOG_LEVEL
  fi
  if [ -z "$level" ]; then
    level=3
  fi
}

test.suite.level $*

echo -e "[96m test.suite starting: $0 <LOG_LEVEL=$level>[0m"
# if [ "$level" -gt "5" ]; then
#     set -x
# fi

test.suite.discover() # # discovers all tests
{
  test.suite.run.completion
}

test.suite.run.completion() # # returns list of available tests for completion
{
  ls $OOSH_DIR/test/* | sed 's/\/.*\/oosh\/test\/\(interactive.\)*test\.//' | grep "^$1"
}

test.suite.parameter.completion.test() # # completion function for test parameter
{
  test.suite.run.completion
}

# ─── test case filter helpers (framework, shared by run + list + completions) ───

private.test.suite.list.names() { # <test> # emit test-case labels from a test file, one per line
  local name="$1"
  [ -z "$name" ] && return 1
  local file="$OOSH_DIR/test/test.$name"
  [ -f "$file" ] || return 1
  # Match `test.case <something> "label" ...` AND `test.def "label" funcName`.
  # Use [^"]* before the first quote (non-greedy) — .*  is greedy and would grab
  # the last quoted string (breaks on lines with a second quoted expect string).
  grep -hE '^[[:space:]]*(test\.case|test\.def)[[:space:]]' "$file" 2>/dev/null \
    | sed -E 's/^[^"]*"([^"]+)".*/\1/'
}

private.test.suite.list.tags() { # <test> # emit tag-before-colon for each label (T-XXX: desc → T-XXX)
  private.test.suite.list.names "$1" | awk -F: '{print $1}' | sort -u
}

test.suite.save.results() # # saves test results to config file and prints summary
{
  source $OOSH_DIR/config
  config.save testresult TEST_SUITE

  # Print final summary
  test.suite.summary
}

test.suite.summary() # # prints test summary with pass/fail counts
{
  local total=$TEST_SUITE_EXPECT_COUNTER
  local passed=$TEST_SUITE_SUCCESS_COUNTER
  local failed=$((total - passed))

  echo ""
  echo -e "\e[1;37m════════════════════════════════════════════════════════════════════\e[0m"
  echo -e "\e[1;37m                         TEST SUMMARY                               \e[0m"
  echo -e "\e[1;37m════════════════════════════════════════════════════════════════════\e[0m"
  echo ""
  echo -e "  Test Cases:  \e[1;37m$TEST_SUITE_TEST_COUNTER\e[0m"
  echo -e "  Assertions:  \e[1;37m$total\e[0m"
  echo -e "  Passed:      \e[1;32m$passed\e[0m"
  if [ "$failed" -gt 0 ]; then
    echo -e "  Failed:      \e[1;31m$failed\e[0m"
  else
    echo -e "  Failed:      \e[1;32m0\e[0m"
  fi
  echo ""

  if [ "$passed" -eq "$total" ] && [ "$total" -gt 0 ]; then
    echo -e "  \e[1;32m✓ ALL TESTS PASSED\e[0m"
  elif [ "$total" -eq 0 ]; then
    echo -e "  \e[1;33m⚠ NO TESTS RUN\e[0m"
  else
    echo -e "  \e[1;31m✗ SOME TESTS FAILED\e[0m"
  fi
  echo ""
  echo -e "\e[1;37m════════════════════════════════════════════════════════════════════\e[0m"
}

test.suite.init() # # initializes test suite counters and environment
{
  source this
  source log
  log.init.colors


  if [ -z "$TEST_COUNTER" ]; then
    declare -i TEST_SUITE_TEST_COUNTER=0
    declare -i TEST_SUITE_EXPECT_COUNTER=0
    declare -i TEST_SUITE_SUCCESS_COUNTER=0
    export SUITE_RESULT="Suite Result: "
  fi

  # Initialize expected error tracking
  export TEST_EXPECTING_ERROR=0
  export TEST_EXPECTED_ERROR_CODE=0

  if (this.isSourced); then
    debug.log "test.suite sourced"
    if [ "$2" = "clear" ]; then
      clear
    fi
    export PS4='\e[90m  ${BASH_SOURCE[0]##*/} -> ${BASH_SOURCE[1]##*/}: ${FUNCNAME[0]}:${LINENO}   - ${BASH_SOURCE[@]##*/} \e[0m'
    if [ "$LOG_LEVEL" -gt "5" ]; then
        set -x
    fi
  else
    #important.log "test.suite started"
    this.start "$@"
  fi
}

test.suite.run() # <test> <?logLevel:3> <?filter> # runs a test, optionally filtered to cases whose label starts with <filter>
{
  # Args type-dispatched so users can put them in any order.
  # First arg matching an existing test/test.<name> file → command.
  # Bare digits 0-7 → log level. Anything else not yet claimed → filter.
  local command="" level="" filter=""
  local arg
  for arg in "$@"; do
    [ -z "$arg" ] && continue
    if [ -z "$command" ] && [ -f "$OOSH_DIR/test/test.$arg" ]; then
      command="$arg"
    elif [ -z "$level" ] && [[ "$arg" =~ ^[0-7]$ ]]; then
      level="$arg"
    elif [ -z "$filter" ]; then
      filter="$arg"
    fi
  done

  if [ -z "$command" ]; then
    error.log "Usage: test.suite run <test> [<logLevel:3>] [<filter>]"
    error.log "  available: $(test.suite.run.completion 2>/dev/null | tr '\n' ' ')"
    return 1
  fi

  # Default log level — 3 (info) is the right default for human consumption.
  [ -z "$level" ] && level=3

  # Export filter so test.case (in this shell) honors it. Empty = run all (back-compat).
  export TEST_CASE_FILTER="$filter"

  # Print test header
  echo ""
  echo -e "\e[1;36m╔════════════════════════════════════════════════════════════════════╗\e[0m"
  echo -e "\e[1;36m║  RUNNING TEST: test.$command${filter:+  [filter: $filter]}\e[0m"
  echo -e "\e[1;36m╚════════════════════════════════════════════════════════════════════╝\e[0m"
  echo ""

  if [ "$level" -gt 0 ]; then
    important.log "starting test: $OOSH_DIR/test/test.$command -level:$level- -filter:${filter:-*}-"
    $OOSH_DIR/test/test.$command $level
  else
    $OOSH_DIR/test/test.$command $level >/dev/null
  fi
  unset TEST_CASE_FILTER

  if check file $CONFIG_PATH/testresult.env exists; then
    source $CONFIG_PATH/testresult.env
  fi

  # Print results
  echo ""
  echo -e "\e[1;37m────────────────────────────────────────────────────────────────────\e[0m"
  echo -e "  Completed: \e[1;37mtest.$command\e[0m"
  echo -e "  Results:   \e[1;32m$TEST_SUITE_SUCCESS_COUNTER\e[0m / $TEST_SUITE_EXPECT_COUNTER assertions passed"
  echo -e "\e[1;37m────────────────────────────────────────────────────────────────────\e[0m"

  if [ "$TEST_SUITE_SUCCESS_COUNTER" -eq "$TEST_SUITE_EXPECT_COUNTER" ]; then
    echo -e "\e[1;32m  ✓ All tests successful\e[0m"
    return 0
  else
    echo -e "\e[1;31m  ✗ Some tests failed\e[0m"
    return 1
  fi
}
test.suite.run.completion.test() { test.suite.run.completion "$@"; }
test.suite.run.completion.logLevel() { for l in 0 1 2 3 4 5; do echo "$l"; done; }
test.suite.run.completion.filter() {
  # c2 calls with ($cur, $class, $method, $arg1, $arg2, …).
  # arg1 is the already-typed <test> script name. $1 is the current word.
  # We need the test script name — it's the first positional after $cur/class/method.
  # Practical fallback: try $1 as script name, else last non-empty arg.
  local test_name=""
  # Walk through args, find an arg that maps to an existing test file
  local a
  for a in "$@"; do
    [ -z "$a" ] && continue
    [ -f "$OOSH_DIR/test/test.$a" ] && test_name="$a"
  done
  [ -z "$test_name" ] && return 0
  # Emit full labels AND tag-only form so either prefix matches
  {
    private.test.suite.list.names "$test_name"
    private.test.suite.list.tags  "$test_name"
  } | sort -u | grep "^$1" 2>/dev/null
}

test.suite.list() # <test> # list all test-case labels from the test file
{
  local name="$1"
  if [ -z "$name" ]; then
    error.log "Usage: test.suite list <test>"
    return 1
  fi
  local file="$OOSH_DIR/test/test.$name"
  if [ ! -f "$file" ]; then
    error.log "No test file: $file"
    return 1
  fi
  # Annotate each label with its source-line number for navigation.
  # Includes both legacy test.case and the newer test.def helpers.
  # Use [^"]* before the first quote (not .*) — .* is greedy and grabs the
  # last quoted string when a test.case has both a label and an echo "$var".
  grep -nE '^[[:space:]]*(test\.case|test\.def)[[:space:]]' "$file" \
    | sed -E 's|^([0-9]+):[^"]*"([^"]+)".*|\2\t(line \1)|'
}
test.suite.list.completion.test() { test.suite.run.completion "$@"; }

test.suite.all() # <?logLevel:1> # runs all tests from the test folder
{
  local level=$1
  if [ -z "$level" ]; then
    level=1
  fi
  shift
  local clear=$1
  shift

  # Initialize cumulative counters
  local -i CUMULATIVE_TEST_COUNTER=0
  local -i CUMULATIVE_EXPECT_COUNTER=0
  local -i CUMULATIVE_SUCCESS_COUNTER=0
  local -i FILE_COUNT=0
  local -i TOTAL_FILES=$(ls -1 $OOSH_DIR/test/test.* 2>/dev/null | grep -v "test\.data" | wc -l)

  # Track intentional failures from meta-test (test.test.suite)
  local -i META_TEST_FAILURES=0
  local META_TEST_RAN=0

  # Print suite header
  echo ""
  echo -e "\e[1;35m╔════════════════════════════════════════════════════════════════════╗\e[0m"
  echo -e "\e[1;35m║                    RUNNING ALL TESTS                               ║\e[0m"
  echo -e "\e[1;35m║                    Log Level: $level                                       ║\e[0m"
  echo -e "\e[1;35m╚════════════════════════════════════════════════════════════════════╝\e[0m"

  for file in $OOSH_DIR/test/test.*
  do
    # Skip test.data directory
    if [ -d "$file" ]; then
      continue
    fi

    ((FILE_COUNT++))
    local filename=$(basename "$file")

    # Reset per-file counters
    local FILE_START_TEST=$TEST_SUITE_TEST_COUNTER
    local FILE_START_EXPECT=$TEST_SUITE_EXPECT_COUNTER
    local FILE_START_SUCCESS=$TEST_SUITE_SUCCESS_COUNTER

    # Print test file header
    echo ""
    echo -e "\e[1;36m╔════════════════════════════════════════════════════════════════════╗\e[0m"
    echo -e "\e[1;36m║  [$FILE_COUNT/$TOTAL_FILES] $filename\e[0m"
    echo -e "\e[1;36m╚════════════════════════════════════════════════════════════════════╝\e[0m"

    # Run the test file
    if [ "$level" -gt 0 ]; then
      $file $level $clear
    else
      $file $level $clear >/dev/null
    fi

    # Load results if saved
    if check file $CONFIG_PATH/testresult.env exists; then
      source $CONFIG_PATH/testresult.env
    fi

    # Calculate per-file results
    local FILE_TESTS=$((TEST_SUITE_TEST_COUNTER - FILE_START_TEST))
    local FILE_EXPECTS=$((TEST_SUITE_EXPECT_COUNTER - FILE_START_EXPECT))
    local FILE_SUCCESS=$((TEST_SUITE_SUCCESS_COUNTER - FILE_START_SUCCESS))
    local FILE_FAILED=$((FILE_EXPECTS - FILE_SUCCESS))

    # Track meta-test (test.test.suite) failures separately
    # This test has 1 INTENTIONAL failure to verify counter logic works
    if [ "$filename" = "test.test.suite" ]; then
      META_TEST_RAN=1
      META_TEST_FAILURES=$FILE_FAILED
    fi

    # Update cumulative counters
    CUMULATIVE_TEST_COUNTER=$TEST_SUITE_TEST_COUNTER
    CUMULATIVE_EXPECT_COUNTER=$TEST_SUITE_EXPECT_COUNTER
    CUMULATIVE_SUCCESS_COUNTER=$TEST_SUITE_SUCCESS_COUNTER

    # Show per-file summary only if LOG_LEVEL > 1
    if [ "$level" -gt 1 ]; then
      echo ""
      echo -e "\e[1;37m────────────────────────────────────────────────────────────────────\e[0m"
      echo -e "  File: \e[1;37m$filename\e[0m"
      echo -e "  Results: \e[1;32m$FILE_SUCCESS\e[0m / $FILE_EXPECTS assertions"
      if [ "$FILE_SUCCESS" -eq "$FILE_EXPECTS" ] && [ "$FILE_EXPECTS" -gt 0 ]; then
        echo -e "  \e[1;32m✓ PASS\e[0m"
      elif [ "$FILE_EXPECTS" -eq 0 ]; then
        echo -e "  \e[1;33m⚠ NO ASSERTIONS\e[0m"
      elif [ "$filename" = "test.test.suite" ] && [ "$FILE_FAILED" -eq 1 ]; then
        echo -e "  \e[1;32m✓ PASS (1 intentional failure - meta-test working correctly)\e[0m"
      else
        echo -e "  \e[1;31m✗ FAIL ($FILE_FAILED failed)\e[0m"
      fi
      echo -e "\e[1;37m────────────────────────────────────────────────────────────────────\e[0m"
    fi
  done

  # Print final overall summary (always shown)
  local TOTAL_FAILED=$((CUMULATIVE_EXPECT_COUNTER - CUMULATIVE_SUCCESS_COUNTER))

  # Check if the ONLY failure is the intentional one from test.test.suite
  local ONLY_INTENTIONAL_FAILURE=0
  if [ "$META_TEST_RAN" -eq 1 ] && [ "$META_TEST_FAILURES" -eq 1 ] && [ "$TOTAL_FAILED" -eq 1 ]; then
    ONLY_INTENTIONAL_FAILURE=1
  fi

  echo ""
  echo -e "\e[1;35m╔════════════════════════════════════════════════════════════════════╗\e[0m"
  echo -e "\e[1;35m║                    FINAL TEST SUITE SUMMARY                        ║\e[0m"
  echo -e "\e[1;35m╚════════════════════════════════════════════════════════════════════╝\e[0m"
  echo ""
  echo -e "  Test Files:  \e[1;37m$FILE_COUNT\e[0m"
  echo -e "  Test Cases:  \e[1;37m$CUMULATIVE_TEST_COUNTER\e[0m"
  echo -e "  Assertions:  \e[1;37m$CUMULATIVE_EXPECT_COUNTER\e[0m"
  echo -e "  Passed:      \e[1;32m$CUMULATIVE_SUCCESS_COUNTER\e[0m"
  if [ "$ONLY_INTENTIONAL_FAILURE" -eq 1 ]; then
    echo -e "  Failed:      \e[1;32m1 (intentional meta-test)\e[0m"
  elif [ "$TOTAL_FAILED" -gt 0 ]; then
    echo -e "  Failed:      \e[1;31m$TOTAL_FAILED\e[0m"
  else
    echo -e "  Failed:      \e[1;32m0\e[0m"
  fi
  echo ""

  if [ "$CUMULATIVE_SUCCESS_COUNTER" -eq "$CUMULATIVE_EXPECT_COUNTER" ] && [ "$CUMULATIVE_EXPECT_COUNTER" -gt 0 ]; then
    echo -e "  \e[1;32m✓ ALL TESTS PASSED\e[0m"
    return 0
  elif [ "$CUMULATIVE_EXPECT_COUNTER" -eq 0 ]; then
    echo -e "  \e[1;33m⚠ NO TESTS RUN\e[0m"
    return 1
  elif [ "$ONLY_INTENTIONAL_FAILURE" -eq 1 ]; then
    echo -e "  \e[1;32m╔══════════════════════════════════════════════════════════════════╗\e[0m"
    echo -e "  \e[1;32m║  ✓ ALL TESTS PASSED                                              ║\e[0m"
    echo -e "  \e[1;32m║    (1 intentional failure in test.test.suite verifies counters)  ║\e[0m"
    echo -e "  \e[1;32m╚══════════════════════════════════════════════════════════════════╝\e[0m"
    return 0
  else
    echo -e "  \e[1;31m✗ SOME TESTS FAILED\e[0m"
    return 1
  fi
}

test.case() # <logLevel:-> <testName> <testFunction> <testArguments> # runs a test case and captures result
{
  local level=$1
  shift
  export testName=$1
  shift
  local testFunction="$1"
  shift
  local testArguments="$@"

  # Framework filter: when TEST_CASE_FILTER is set, skip cases whose label or
  # tag-before-colon does NOT start with the filter value. Skipped cases do
  # NOT advance TEST_SUITE_TEST_COUNTER and produce no output. We also set
  # TEST_CASE_SKIPPED=y so subsequent stray expect.pass/expect.fail calls
  # (outside a case body but tied to it by convention) are no-ops.
  # Reset RETURN_VALUE/RESULT to safe defaults so any inline `if [ "$RETURN_VALUE"
  # -eq 0 ]` checks (which the test files write *after* a test.case call) don't
  # crash with "integer expression expected".
  if [ -n "${TEST_CASE_FILTER:-}" ]; then
    local __tag="${testName%%:*}"
    local __pass=""
    case "$testName" in "$TEST_CASE_FILTER"*) __pass=y ;; esac
    case "$__tag"     in "$TEST_CASE_FILTER"*) __pass=y ;; esac
    if [ -z "$__pass" ]; then
      export TEST_CASE_SKIPPED=y
      RETURN_VALUE=0
      RESULT=""
      return 0
    fi
  fi
  # Case is (going to be) executed — clear the skip flag so later expects count.
  export TEST_CASE_SKIPPED=""

  ((TEST_SUITE_TEST_COUNTER++))

  if ! [ "$level" = "-" ]; then
    log.level $level
  fi
  if [ "$LOG_LEVEL" -gt "5" ]; then
      set -x
  fi

  # Print test case header
  echo ""
  echo -e "\e[1;37m┌──────────────────────────────────────────────────────────────────┐\e[0m"
  echo -e "\e[1;37m│ Test $TEST_SUITE_TEST_COUNTER: $testName\e[0m"
  echo -e "\e[1;37m└──────────────────────────────────────────────────────────────────┘\e[0m"

  if [ "$LOG_LEVEL" -gt "2" ]; then
    echo -e "\e[90m  → $testFunction $testArguments\e[0m"
  fi

  # Check if we're expecting an error
  if [ "$TEST_EXPECTING_ERROR" -eq 1 ]; then
    # Capture stderr and suppress error output for expected errors
    {
      $testFunction $testArguments
      RETURN_VALUE=$?
    } 2>/dev/null

    if [ "$RETURN_VALUE" -eq "$TEST_EXPECTED_ERROR_CODE" ]; then
      echo -e "\e[1;32m  ✓ EXPECTED ERROR (code $RETURN_VALUE) - OK\e[0m"
    else
      echo -e "\e[1;33m  ⚠ Expected error code $TEST_EXPECTED_ERROR_CODE but got $RETURN_VALUE\e[0m"
    fi

    # Reset expected error state
    TEST_EXPECTING_ERROR=0
    TEST_EXPECTED_ERROR_CODE=0
  else
    # Normal test execution - suppress stderr to hide internal errors
    # Errors will be shown in assertions
    if [ "$LOG_LEVEL" -gt "2" ]; then
      $testFunction $testArguments
      RETURN_VALUE=$?
    else
      {
        $testFunction $testArguments
        RETURN_VALUE=$?
      } 2>/dev/null
    fi

    # Don't call onError here - let the assertions handle pass/fail reporting
  fi

  if [ "$LOG_LEVEL" -gt "2" ]; then
    echo -e "\e[90m  ← RETURN: $RETURN_VALUE  Result: $RESULT\e[0m"
  fi
}

# ─── test.def: each test as a NAMED FUNCTION (callable directly) ──────────────
# Pattern in a test file:
#   __test_pull_8() {
#     ... body ...
#     # internal expect.pass / expect.fail
#   }
#   test.def "T-PULL-8: JSONL loop processes all snapshot entries" __test_pull_8
#
# Benefits over inline test.case:
#   - The test body is a real bash function — callable from any shell for
#     iteration: just run `__test_pull_8` directly.
#   - Filter mode runs ONLY the matching function — no surrounding setup
#     between cases re-executes (the function owns its own setup/teardown).
#   - Counters and filter still flow through test.case for harness integration.
#
# test.def delegates to test.case so filter, counters, and skip-flag behavior
# stay in one place. The function is independently invocable either way.
test.def() # <label> <funcName> # register a test as a named, callable function
{
  local label="$1" fn="$2"
  if [ -z "$label" ] || [ -z "$fn" ]; then
    error.log "Usage: test.def <label> <funcName>"
    return 1
  fi
  if ! type -t "$fn" >/dev/null 2>&1; then
    error.log "test.def: function '$fn' is not defined — define it before calling test.def"
    return 1
  fi
  test.case "-" "$label" "$fn"
}
test.def.completion.label() {
  # Bash completes against current registry; functions follow OOSH conv.
  echo "T-MY-CASE-1:"
}

test.case.expect.error() # <errorCode> <testName> <testFunction> <testArguments> # runs test case expecting specific error
{
  local errorCode=$1
  shift

  # Set expected error state
  export TEST_EXPECTING_ERROR=1
  export TEST_EXPECTED_ERROR_CODE=$errorCode
  export EXPECTED_RETURN_VALUE=$errorCode

  # Run test case with remaining args (level is "-" to preserve log level)
  test.case "-" "$@"
}

expect() # <returnValue> <expectedResult> <?message> # asserts test result matches expected
{
  [ "${TEST_CASE_SKIPPED:-}" = "y" ] && return 0
  ((TEST_SUITE_EXPECT_COUNTER++))

  let EXPECTED_RETURN_VALUE=$1
  shift
  local expectedresult="$1"
  shift
  local message="$1"
  shift

  declare -i rv=$RETURN_VALUE
  #console.log "${BOLD_CYAN}starting on testcase: \#$TEST_COUNTER - $testcase${NORMAL}"

  if [ -z "$message" ]; then
    message=$testName
  fi

  if [ "$expectedresult" = "*" ]; then
    expectedresult=$RESULT
  fi

  if [ "$EXPECTED_RETURN_VALUE" = "*" ]; then
    EXPECTED_RETURN_VALUE=$RETURN_VALUE
  fi

  if [ "$EXPECTED_RETURN_VALUE" -eq $rv ] && [ "$RESULT" = "$expectedresult" ]; then
    ((TEST_SUITE_SUCCESS_COUNTER++))
    echo -e "\e[1;32m  ✓ PASS:\e[0m $message"
  else
    echo -e "\e[1;31m  ✗ FAIL:\e[0m $message"
    echo -e "\e[90m    Expected return: $EXPECTED_RETURN_VALUE, got: $RETURN_VALUE\e[0m"
    if [ "$expectedresult" != "$RESULT" ]; then
      echo -e "\e[90m    Expected result: $expectedresult\e[0m"
      echo -e "\e[90m    Got result:      $RESULT\e[0m"
    fi
  fi

  TEST_SUITE_RESULT="\e[1;32m$TEST_SUITE_SUCCESS_COUNTER\e[0m / $TEST_SUITE_EXPECT_COUNTER expects on $TEST_SUITE_TEST_COUNTER Tests"
}

expect.pass() # <?message> # simple pass assertion with optional message
{
  [ "${TEST_CASE_SKIPPED:-}" = "y" ] && return 0
  ((TEST_SUITE_EXPECT_COUNTER++))
  ((TEST_SUITE_SUCCESS_COUNTER++))

  local message="$1"
  if [ -z "$message" ]; then
    message="assertion passed"
  fi
  echo -e "\e[1;32m  ✓ PASS:\e[0m $message"
}

expect.fail() # <?message> # simple fail assertion with optional message
{
  [ "${TEST_CASE_SKIPPED:-}" = "y" ] && return 0
  ((TEST_SUITE_EXPECT_COUNTER++))

  local message="$1"
  if [ -z "$message" ]; then
    message="assertion failed"
  fi
  echo -e "\e[1;31m  ✗ FAIL:\e[0m $message"
}

test.suite.usage() # # displays usage information for test.suite
{
  local this=${0##*/}
  echo "You started
$0

  current log level: $LOG_LEVEL

  current file: $CONFIG
   CONFIG_PATH=$CONFIG_PATH
   CONFIG_FILE=$CONFIG_FILE


  Usage:
  $this: command   description and Parameter
      all       tests all tests in $OOSH_DIR/test
                $this all <log level>  <?clear>
      run       runs a single test: $OOSH_DIR/test/test.<command>
                $this <command> <log level>  <?clear>


  Examples
    $this run loop 5
    $this all 1 clear
  "

  #loop.list PATH print '---------------------: '
}

test.suite.init "$@"
