Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48b436b20a | ||
|
|
616aa6f2f1
|
||
|
|
1129563000 | ||
|
|
9ab65a6b1f
|
@@ -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
|
||||||
@@ -52,6 +52,9 @@ Options:
|
|||||||
--[no-]copy Copy result to clipboard
|
--[no-]copy Copy result to clipboard
|
||||||
--[no-]notify Show desktop notification
|
--[no-]notify Show desktop notification
|
||||||
--desktop GUI mode: pick → copy → notify
|
--desktop GUI mode: pick → copy → notify
|
||||||
|
--get-config Print the current configuration
|
||||||
|
--set-config Update the configuration (e.g. --set-config desktop --copy)
|
||||||
|
--reset-config Restore the configuration file to its default values
|
||||||
--install Install to ~/.local/share/ and symlink to ~/.local/bin/
|
--install Install to ~/.local/share/ and symlink to ~/.local/bin/
|
||||||
--help, -h Show this help message
|
--help, -h Show this help message
|
||||||
```
|
```
|
||||||
@@ -102,6 +105,22 @@ copy = true # copy result to clipboard
|
|||||||
notify = true # show desktop notification with the copied value
|
notify = true # show desktop notification with the copied value
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also use the CLI to manage your configuration:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# View current config
|
||||||
|
color-tool --get-config
|
||||||
|
|
||||||
|
# Update specific keys (e.g., enable swatch by default)
|
||||||
|
color-tool --set-config defaults --swatch
|
||||||
|
|
||||||
|
# Set output format for desktop mode
|
||||||
|
color-tool --set-config desktop output=rgba
|
||||||
|
|
||||||
|
# Reset to factory defaults
|
||||||
|
color-tool --reset-config
|
||||||
|
```
|
||||||
|
|
||||||
## 🧪 Testing
|
## 🧪 Testing
|
||||||
|
|
||||||
The project includes a comprehensive test suite that verifies color conversion, configuration loading, and system integrations (clipboard/notifications) using mocks.
|
The project includes a comprehensive test suite that verifies color conversion, configuration loading, and system integrations (clipboard/notifications) using mocks.
|
||||||
|
|||||||
+68
-1
@@ -47,7 +47,18 @@ ln -s /usr/bin/mkdir "$BIN_DIR/mkdir"
|
|||||||
ln -s /usr/bin/mktemp "$BIN_DIR/mktemp"
|
ln -s /usr/bin/mktemp "$BIN_DIR/mktemp"
|
||||||
ln -s /usr/bin/chmod "$BIN_DIR/chmod"
|
ln -s /usr/bin/chmod "$BIN_DIR/chmod"
|
||||||
ln -s /usr/bin/rm "$BIN_DIR/rm"
|
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 PATH="$BIN_DIR"
|
||||||
export HOME="$TEST_DIR"
|
export HOME="$TEST_DIR"
|
||||||
@@ -139,6 +150,62 @@ else
|
|||||||
echo "FAIL (notify.log not created)"
|
echo "FAIL (notify.log not created)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 8. Config Management
|
||||||
|
it "manages configuration via CLI"
|
||||||
|
mkdir -p "$HOME/.config/color-tool"
|
||||||
|
"$COLOR_TOOL" --reset-config >/dev/null
|
||||||
|
|
||||||
|
# Test --set-config
|
||||||
|
"$COLOR_TOOL" --set-config defaults output=rgba
|
||||||
|
output=$("$COLOR_TOOL" --get-config)
|
||||||
|
if [[ "$output" == *"output = \"rgba\""* ]]; then
|
||||||
|
# Test --reset-config
|
||||||
|
"$COLOR_TOOL" --reset-config >/dev/null
|
||||||
|
output=$("$COLOR_TOOL" --get-config)
|
||||||
|
assert_contains "$output" "output = \"hex\""
|
||||||
|
else
|
||||||
|
echo "FAIL"
|
||||||
|
echo " Expected to find: output = \"rgba\""
|
||||||
|
echo " Actual output: $output"
|
||||||
|
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 ───────────────────────────────────────────────────────────────────
|
# ── Cleanup ───────────────────────────────────────────────────────────────────
|
||||||
echo "---------------------------------------"
|
echo "---------------------------------------"
|
||||||
echo "Result: $passed/$total tests passed."
|
echo "Result: $passed/$total tests passed."
|
||||||
|
|||||||
Reference in New Issue
Block a user