Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
test:
name: Run ZSH Configuration Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run tests
run: |
bash tests/run_tests.sh

- name: Test Summary
if: always()
run: |
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Tests completed. Check the logs above for details." >> $GITHUB_STEP_SUMMARY
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,34 @@ zdotdir/
export ZDOTDIR="$HOME/.config/zsh"
```

## Testing

This repository includes a comprehensive test suite to verify that the configuration is properly structured and that important tools are correctly integrated.

### Running Tests

Run all tests:
```bash
./tests/run_tests.sh
```

Run specific test files:
```bash
./tests/run_tests.sh "test_core_tools.sh"
```

### Test Coverage

The test suite includes:

- **Core Tools Integration**: Tests for mise, fzf, and zoxide configuration
- **Configuration Files**: Tests for .zshrc, .zshenv, .zprofile structure
- **Custom Functions**: Tests for autoloaded functions in the `functions/` directory
- **Aliases**: Tests for alias definitions
- **Custom Commands**: Tests for shell functions in rc.d/06-commands.zsh

For more details, see [tests/README.md](tests/README.md).

## Aliases Documentation

This document provides a comprehensive list of all available aliases organized by category.
Expand Down
156 changes: 156 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# ZSH Configuration Tests

This directory contains tests for the ZSH configuration. The tests verify that the configuration files are properly structured and that important tools like mise, fzf, and zoxide are correctly integrated.

## Test Structure

```
tests/
├── run_tests.sh # Main test runner
├── test_helpers.sh # Test assertion functions and utilities
├── integration/ # Integration tests
│ └── test_core_tools.sh # Tests for mise, fzf, zoxide integration
└── unit/ # Unit tests
├── test_aliases.sh # Tests for alias definitions
├── test_commands.sh # Tests for custom shell functions
├── test_config.sh # Tests for ZSH configuration files
└── test_functions.sh # Tests for autoloaded functions
```

## Running Tests

### Run All Tests

```bash
./tests/run_tests.sh
```

### Run Specific Test Files

You can run specific test files by passing a pattern:

```bash
./tests/run_tests.sh "test_core_tools.sh"
```

Or run tests from a specific directory:

```bash
bash tests/unit/test_config.sh
```

## Test Categories

### Integration Tests

**Core Tools Integration** (`integration/test_core_tools.sh`)
- Verifies mise configuration file exists and has proper content
- Verifies fzf configuration file exists and has proper content
- Verifies zoxide configuration file exists and has proper content
- Tests command check patterns (returns 1 when command is missing)
- Ensures configuration files are minimal and focused

### Unit Tests

**Custom Functions** (`unit/test_functions.sh`)
- Tests that all function files exist in the `functions/` directory
- Verifies functions have proper shebangs
- Tests specific function content (bench-startup, grecent, etc.)
- Checks that functions use expected tools (fzf, git, jq, etc.)

**ZSH Configuration Files** (`unit/test_config.sh`)
- Tests main configuration files exist (.zshrc, .zshenv, .zprofile)
- Verifies configuration content (antidote loading, rc.d sourcing)
- Tests rc.d file structure and naming conventions
- Verifies environment variables are set correctly

**Aliases** (`unit/test_aliases.sh`)
- Tests that alias file exists and has content
- Verifies common aliases are defined
- Checks alias syntax is correct

**Custom Commands** (`unit/test_commands.sh`)
- Tests that command functions are defined
- Verifies integration with fzf and jq
- Tests PostgreSQL functions use mise
- Checks function documentation

## Test Helpers

The `test_helpers.sh` file provides several assertion functions:

- `assert_success(description, command)` - Asserts command succeeds
- `assert_failure(description, command)` - Asserts command fails
- `assert_equals(description, expected, actual)` - Asserts equality
- `assert_contains(description, haystack, needle)` - Asserts substring match
- `assert_file_exists(description, file)` - Asserts file exists
- `assert_command_exists(description, command)` - Asserts command is available

## Test Output

Tests produce colored output:
- ✓ Green for passed tests
- ✗ Red for failed tests
- ℹ Yellow for informational messages

Example output:
```
Running test suite: Core Tools Integration
================================
✓ mise.zsh configuration file exists
✓ fzf.zsh configuration file exists
✓ zoxide.zsh configuration file exists
...

================================
Test Summary
================================
Total: 15
Passed: 15
Failed: 0
```

## Adding New Tests

To add new tests:

1. Create a new test file in `tests/unit/` or `tests/integration/`
2. Name it `test_*.sh` (e.g., `test_my_feature.sh`)
3. Make it executable: `chmod +x tests/unit/test_my_feature.sh`
4. Source the test helpers: `source "$SCRIPT_DIR/../test_helpers.sh"`
5. Use `run_test_suite "Your Suite Name"` to start the suite
6. Add your test assertions using the helper functions
7. End with `print_summary` to show results

Example test file:

```bash
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
source "$SCRIPT_DIR/../test_helpers.sh"

run_test_suite "My Feature Tests"

assert_file_exists "my config exists" "$REPO_ROOT/my_config.zsh"
assert_contains "config has setting" "$(cat $REPO_ROOT/my_config.zsh)" "my_setting"

print_summary
```

## Continuous Integration

These tests can be run in CI environments. The test runner exits with:
- Exit code 0 if all tests pass
- Exit code 1 if any tests fail

This makes it easy to integrate with GitHub Actions or other CI systems.

## Requirements

The tests are written in bash and use standard Unix tools:
- bash (for running tests)
- grep, awk, sed (for text processing)
- Standard file operations (cat, ls, wc)

No ZSH is required to run the tests - they verify the configuration files themselves, not their runtime behavior.
108 changes: 108 additions & 0 deletions tests/integration/test_core_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash
# Integration tests for core tools: mise, fzf, zoxide
# These tests verify that the tool integration files work correctly

# Get the directory of this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

# Source test helpers
source "$SCRIPT_DIR/../test_helpers.sh"

run_test_suite "Core Tools Integration"

# Test mise configuration file
assert_file_exists "mise.zsh configuration file exists" "$REPO_ROOT/rc.d/mise.zsh"

# Test fzf configuration file
assert_file_exists "fzf.zsh configuration file exists" "$REPO_ROOT/rc.d/fzf.zsh"

# Test zoxide configuration file
assert_file_exists "zoixide.zsh configuration file exists" "$REPO_ROOT/rc.d/zoixide.zsh"

# Test mise configuration content
test_mise_config() {
local content=$(cat "$REPO_ROOT/rc.d/mise.zsh")

assert_contains "mise.zsh checks for mise command" "$content" '\$+commands\[mise\]'
assert_contains "mise.zsh activates mise" "$content" "mise activate zsh"
}

test_mise_config

# Test fzf configuration content
test_fzf_config() {
local content=$(cat "$REPO_ROOT/rc.d/fzf.zsh")

assert_contains "fzf.zsh checks for fzf command" "$content" '\$+commands\[fzf\]'
assert_contains "fzf.zsh sources fzf integration" "$content" "fzf --zsh"
}

test_fzf_config

# Test zoxide configuration content
test_zoxide_config() {
local content=$(cat "$REPO_ROOT/rc.d/zoixide.zsh")

assert_contains "zoixide.zsh checks for zoxide command" "$content" '\$+commands\[zoxide\]'
assert_contains "zoixide.zsh initializes zoxide" "$content" "zoxide init zsh"
}

test_zoxide_config

# Test that config files return 1 when command is missing
test_command_check_pattern() {
# All three files should use the same pattern for command checking
local mise_first_line=$(head -n 1 "$REPO_ROOT/rc.d/mise.zsh")
local fzf_first_line=$(head -n 1 "$REPO_ROOT/rc.d/fzf.zsh")
local zoxide_first_line=$(head -n 1 "$REPO_ROOT/rc.d/zoixide.zsh")

# Check that they all follow the pattern: (($+commands[tool])) || return 1
assert_contains "mise.zsh has proper command check" "$mise_first_line" "return 1"
assert_contains "fzf.zsh has proper command check" "$fzf_first_line" "return 1"
assert_contains "zoixide.zsh has proper command check" "$zoxide_first_line" "return 1"
}

test_command_check_pattern

# Test that configuration files are minimal
test_config_minimalism() {
local mise_lines=$(wc -l < "$REPO_ROOT/rc.d/mise.zsh")
local fzf_lines=$(wc -l < "$REPO_ROOT/rc.d/fzf.zsh")
local zoxide_lines=$(wc -l < "$REPO_ROOT/rc.d/zoixide.zsh")

# Each file should be very minimal (less than 10 lines)
if [ "$mise_lines" -le 10 ]; then
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_PASSED=$((TESTS_PASSED + 1))
print_green "✓ mise.zsh is minimal ($mise_lines lines)"
else
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
print_red "✗ mise.zsh should be minimal (has $mise_lines lines)"
fi

if [ "$fzf_lines" -le 10 ]; then
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_PASSED=$((TESTS_PASSED + 1))
print_green "✓ fzf.zsh is minimal ($fzf_lines lines)"
else
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
print_red "✗ fzf.zsh should be minimal (has $fzf_lines lines)"
fi

if [ "$zoxide_lines" -le 10 ]; then
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_PASSED=$((TESTS_PASSED + 1))
print_green "✓ zoixide.zsh is minimal ($zoxide_lines lines)"
else
TESTS_RUN=$((TESTS_RUN + 1))
TESTS_FAILED=$((TESTS_FAILED + 1))
print_red "✗ zoixide.zsh should be minimal (has $zoxide_lines lines)"
fi
}

test_config_minimalism

print_summary
Loading