From ef0940daa8114f0db26de0c7d6af33f1fcf305bd Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Mon, 16 Mar 2026 13:46:25 +0300 Subject: Enha(cli): add sort img test case --- cli-tests/sort-img/check.sh | 74 ++++++++++++++++++++++++++++++++++++++++++ cli-tests/sort-img/run.sh | 25 ++++++++++++++ cli-tests/sort-img/setup.sh | 9 +++++ cli-tests/sort-img/teardown.sh | 4 +++ cli-tests/sort-text/check.sh | 2 +- 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100755 cli-tests/sort-img/check.sh create mode 100755 cli-tests/sort-img/run.sh create mode 100755 cli-tests/sort-img/setup.sh create mode 100755 cli-tests/sort-img/teardown.sh (limited to 'cli-tests') diff --git a/cli-tests/sort-img/check.sh b/cli-tests/sort-img/check.sh new file mode 100755 index 0000000..3efc9d2 --- /dev/null +++ b/cli-tests/sort-img/check.sh @@ -0,0 +1,74 @@ +#!/bin/bash +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +LOG_FILE=$(ls -t "$SCRIPT_DIR"/*_run.log 2>/dev/null | head -1) + +PASS=0 +FAIL=0 + +log_pass() { + echo "[PASS] $1" + PASS=$((PASS + 1)) +} + +log_fail() { + echo "[FAIL] $1" + FAIL=$((FAIL + 1)) +} + +echo "=== Checking results ===" +echo "" + +# Check has-animals directory exists +if [ -d "/tmp/sort-img/has-animals" ]; then + log_pass "has-animals directory exists" +else + log_fail "has-animals directory missing" +fi + +# Check no-animals directory exists +if [ -d "/tmp/sort-img/no-animals" ]; then + log_pass "no-animals directory exists" +else + log_fail "no-animals directory missing" +fi + +# Check has-animals contains at least one image +HAS_ANIMALS_FILES=$(ls -1 /tmp/sort-img/has-animals 2>/dev/null | wc -l) +if [ "$HAS_ANIMALS_FILES" -gt 0 ]; then + log_pass "has-animals contains images ($HAS_ANIMALS_FILES files)" +else + log_fail "has-animals is empty" +fi + +# Check no-animals contains at least one image +NO_ANIMALS_FILES=$(ls -1 /tmp/sort-img/no-animals 2>/dev/null | wc -l) +if [ "$NO_ANIMALS_FILES" -gt 0 ]; then + log_pass "no-animals contains images ($NO_ANIMALS_FILES files)" +else + log_fail "no-animals is empty" +fi + +# Check total files sorted correctly (3 original files should be in subdirs) +TOTAL_SORTED=$((HAS_ANIMALS_FILES + NO_ANIMALS_FILES)) +if [ "$TOTAL_SORTED" -eq 3 ]; then + log_pass "all 3 files sorted into subdirectories" +else + log_fail "expected 3 files sorted, got $TOTAL_SORTED" +fi + +echo "" +echo "=== Summary ===" +echo "PASSED: $PASS" +echo "FAILED: $FAIL" + +if [ $FAIL -gt 0 ]; then + echo "" + echo "Log file: $LOG_FILE" + exit 1 +fi + +echo "" +echo "All tests passed!" +exit 0 diff --git a/cli-tests/sort-img/run.sh b/cli-tests/sort-img/run.sh new file mode 100755 index 0000000..5cd5d3e --- /dev/null +++ b/cli-tests/sort-img/run.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +TIMESTAMP=$(date +%Y%m%d_%H%M%S) +LOG_FILE="$SCRIPT_DIR/${TIMESTAMP}_run.log" + +exec > "$LOG_FILE" 2>&1 + +echo "=== Running teardown ===" +"$SCRIPT_DIR/teardown.sh" + +echo "" +echo "=== Running setup ===" +"$SCRIPT_DIR/setup.sh" + +echo "" +echo "=== Running task ===" +TASK=$(cat "$SCRIPT_DIR/task.txt") +cd /home/grail/projects/plays/goplays/gf-lt +go run . -cli -msg "$TASK" + +echo "" +echo "=== Done ===" +echo "Log file: $LOG_FILE" diff --git a/cli-tests/sort-img/setup.sh b/cli-tests/sort-img/setup.sh new file mode 100755 index 0000000..6b89be8 --- /dev/null +++ b/cli-tests/sort-img/setup.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +mkdir -p /tmp/sort-img + +cp ../../../assets/ex01.png /tmp/sort-img/file1.png +cp ../../../assets/helppage.png /tmp/sort-img/file2.png +cp ../../../assets/yt_thumb.jpg /tmp/sort-img/file3.jpg diff --git a/cli-tests/sort-img/teardown.sh b/cli-tests/sort-img/teardown.sh new file mode 100755 index 0000000..691155b --- /dev/null +++ b/cli-tests/sort-img/teardown.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +rm -rf /tmp/sort-img diff --git a/cli-tests/sort-text/check.sh b/cli-tests/sort-text/check.sh index 7beb2f5..cc1d1df 100755 --- a/cli-tests/sort-text/check.sh +++ b/cli-tests/sort-text/check.sh @@ -2,7 +2,7 @@ set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -LOG_FILE="$SCRIPT_DIR/run.log" +LOG_FILE=$(ls -t "$SCRIPT_DIR"/*_run.log 2>/dev/null | head -1) PASS=0 FAIL=0 -- cgit v1.2.3