From 7f8bbefb05d85dcbcc560a0fb23256b912676486 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Mon, 16 Mar 2026 06:36:24 +0300 Subject: Chore: add cli test --- cli-tests/sort-text/setup.sh | 10 ++++++++++ cli-tests/sort-text/task.txt | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 cli-tests/sort-text/setup.sh create mode 100644 cli-tests/sort-text/task.txt (limited to 'cli-tests') diff --git a/cli-tests/sort-text/setup.sh b/cli-tests/sort-text/setup.sh new file mode 100644 index 0000000..351ebe2 --- /dev/null +++ b/cli-tests/sort-text/setup.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +mkdir -p /tmp/sort-text + +printf "cat" > /tmp/sort-text/file1.txt +printf "red" > /tmp/sort-text/file2.txt +printf "dog" > /tmp/sort-text/file3.txt +printf "blue" > /tmp/sort-text/file4.txt diff --git a/cli-tests/sort-text/task.txt b/cli-tests/sort-text/task.txt new file mode 100644 index 0000000..0d3a9e8 --- /dev/null +++ b/cli-tests/sort-text/task.txt @@ -0,0 +1,2 @@ +go to /tmp/sort-text, create directories: animals, colors +sort /tmp/sort-text/*.txt into created directories by text content -- cgit v1.2.3 From df04d8c21c4d256ade69f53bfe171f066db943cc Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Mon, 16 Mar 2026 08:38:48 +0300 Subject: Fix: wait for the tool resp --- cli-tests/sort-text/setup.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 cli-tests/sort-text/setup.sh (limited to 'cli-tests') diff --git a/cli-tests/sort-text/setup.sh b/cli-tests/sort-text/setup.sh old mode 100644 new mode 100755 -- cgit v1.2.3 From 3d44686a517f65c6f5a985cfa864240b996fdb99 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Mon, 16 Mar 2026 09:44:28 +0300 Subject: Feat (cli): test run and teardown --- cli-tests/sort-text/check.sh | 91 +++++++++++++++++++++++++++++++++++++++++ cli-tests/sort-text/run.sh | 25 +++++++++++ cli-tests/sort-text/teardown.sh | 4 ++ 3 files changed, 120 insertions(+) create mode 100755 cli-tests/sort-text/check.sh create mode 100755 cli-tests/sort-text/run.sh create mode 100755 cli-tests/sort-text/teardown.sh (limited to 'cli-tests') diff --git a/cli-tests/sort-text/check.sh b/cli-tests/sort-text/check.sh new file mode 100755 index 0000000..7beb2f5 --- /dev/null +++ b/cli-tests/sort-text/check.sh @@ -0,0 +1,91 @@ +#!/bin/bash +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +LOG_FILE="$SCRIPT_DIR/run.log" + +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 animals directory exists +if [ -d "/tmp/sort-text/animals" ]; then + log_pass "animals directory exists" +else + log_fail "animals directory missing" +fi + +# Check colors directory exists +if [ -d "/tmp/sort-text/colors" ]; then + log_pass "colors directory exists" +else + log_fail "colors directory missing" +fi + +# Check animals contain cat/dog +ANIMALS_FILES=$(ls -1 /tmp/sort-text/animals 2>/dev/null | tr '\n' ' ') +if echo "$ANIMALS_FILES" | grep -q "file1.txt" && echo "$ANIMALS_FILES" | grep -q "file3.txt"; then + log_pass "animals contains animal files" +else + log_fail "animals missing animal files (got: $ANIMALS_FILES)" +fi + +# Check colors contain red/blue +COLORS_FILES=$(ls -1 /tmp/sort-text/colors 2>/dev/null | tr '\n' ' ') +if echo "$COLORS_FILES" | grep -q "file2.txt" && echo "$COLORS_FILES" | grep -q "file4.txt"; then + log_pass "colors contains color files" +else + log_fail "colors missing color files (got: $COLORS_FILES)" +fi + +# Verify content +if grep -q "cat" /tmp/sort-text/animals/file1.txt 2>/dev/null; then + log_pass "file1.txt contains 'cat'" +else + log_fail "file1.txt missing 'cat'" +fi + +if grep -q "dog" /tmp/sort-text/animals/file3.txt 2>/dev/null; then + log_pass "file3.txt contains 'dog'" +else + log_fail "file3.txt missing 'dog'" +fi + +if grep -q "red" /tmp/sort-text/colors/file2.txt 2>/dev/null; then + log_pass "file2.txt contains 'red'" +else + log_fail "file2.txt missing 'red'" +fi + +if grep -q "blue" /tmp/sort-text/colors/file4.txt 2>/dev/null; then + log_pass "file4.txt contains 'blue'" +else + log_fail "file4.txt missing 'blue'" +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-text/run.sh b/cli-tests/sort-text/run.sh new file mode 100755 index 0000000..5cd5d3e --- /dev/null +++ b/cli-tests/sort-text/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-text/teardown.sh b/cli-tests/sort-text/teardown.sh new file mode 100755 index 0000000..5a833ce --- /dev/null +++ b/cli-tests/sort-text/teardown.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +rm -rf /tmp/sort-text -- cgit v1.2.3 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 From 0b7f621a75403e1a21b303bae3975a2758d64be8 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Tue, 17 Mar 2026 07:20:19 +0300 Subject: Chore (cli): sort-img task --- cli-tests/sort-img/task.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 cli-tests/sort-img/task.txt (limited to 'cli-tests') diff --git a/cli-tests/sort-img/task.txt b/cli-tests/sort-img/task.txt new file mode 100644 index 0000000..ebf6185 --- /dev/null +++ b/cli-tests/sort-img/task.txt @@ -0,0 +1,2 @@ +go to /tmp/sort-img, create directories: has-animals, no-animals +sort images in /tmp/sort-img into created directories by content -- cgit v1.2.3