From 9ab65a6b1ff0eb8570045124c0c5a567f23a2255 Mon Sep 17 00:00:00 2001 From: rootiest Date: Sat, 2 May 2026 23:30:43 -0400 Subject: [PATCH] ci/test: add gitea workflow and comprehensive test coverage --- .gitea/workflows/test.yaml | 22 ++++++++++++++++ tests/run_tests.sh | 51 +++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/test.yaml diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml new file mode 100644 index 0000000..b24fb14 --- /dev/null +++ b/.gitea/workflows/test.yaml @@ -0,0 +1,22 @@ +name: Test PR + +on: + pull_request: + branches: + - main + +jobs: + test: + if: "!contains(github.event.pull_request.labels.*.name, 'Kind/Documentation')" + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Make scripts executable + run: | + chmod +x color-tool + chmod +x tests/run_tests.sh + + - name: Run test suite + run: ./tests/run_tests.sh diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 32946f1..1576eb5 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -47,7 +47,18 @@ ln -s /usr/bin/mkdir "$BIN_DIR/mkdir" ln -s /usr/bin/mktemp "$BIN_DIR/mktemp" ln -s /usr/bin/chmod "$BIN_DIR/chmod" ln -s /usr/bin/rm "$BIN_DIR/rm" -ln -s /usr/bin/curl "$BIN_DIR/curl" +# Mock curl for thecolorapi.com +cat <<'MOCK' > "$BIN_DIR/curl" +#!/bin/bash +if [[ "$*" == *"thecolorapi.com"* ]]; then + echo '{"name": {"value": "Mocked Color Name"}}' + exit 0 +fi +exec /usr/bin/curl "$@" +MOCK +chmod +x "$BIN_DIR/curl" +ln -s /usr/bin/mv "$BIN_DIR/mv" +ln -s /usr/bin/tr "$BIN_DIR/tr" export PATH="$BIN_DIR" export HOME="$TEST_DIR" @@ -139,6 +150,44 @@ else echo "FAIL (notify.log not created)" fi + +# 9. JSON Output +it "outputs selected formats as JSON" +output=$("$COLOR_TOOL" "#00ff00" --output hex,rgb --json --no-copy --no-notify) +if [[ "$output" == *'"hex": "#00ff00"'* ]] && [[ "$output" == *'"rgb": "rgb(0, 255, 0)"'* ]]; then + echo "PASS" + passed=$((passed + 1)) +else + echo "FAIL" + echo " Actual output: $output" +fi + +# 10. Swatch Output +it "outputs visual swatch" +output=$("$COLOR_TOOL" "#112233" --output hex --swatch --no-copy --no-notify) +if [[ "$output" == *"$(printf "\033[48;2;17;34;51m \033[0m")"* ]] && [[ "$output" == *"#112233"* ]]; then + echo "PASS" + passed=$((passed + 1)) +else + echo "FAIL" + echo " Actual output: $output" +fi + +# 11. Color Name Fetching +it "fetches color name from thecolorapi.com" +output=$("$COLOR_TOOL" "#ffffff" --output hex --name --no-copy --no-notify) +assert_contains "$output" "(Mocked Color Name)" + +# 12. Invalid Color Input +it "rejects invalid colors" +output=$("$COLOR_TOOL" "invalid-color" --no-copy --no-notify 2>&1 || true) +assert_contains "$output" "Error: Invalid color: invalid-color" + +# 13. Invalid Format Input +it "rejects invalid formats" +output=$("$COLOR_TOOL" "#000000" --output badfmt --no-copy --no-notify 2>&1 || true) +assert_contains "$output" "Error: Invalid output format: badfmt" + # ── Cleanup ─────────────────────────────────────────────────────────────────── echo "---------------------------------------" echo "Result: $passed/$total tests passed."