diff --git a/docs/TESTS.md b/docs/TESTS.md index 80f5087..cba9957 100644 --- a/docs/TESTS.md +++ b/docs/TESTS.md @@ -2,6 +2,57 @@ All tests are located alongside source code in the `src/core/` package. Tests follow Go conventions with `*_test.go` filename patterns. +## Running Tests + +### Using the test scripts + +The repository provides convenience scripts to run all tests with static analysis: + +**Unix/Linux/macOS:** +```bash +./scripts/test.sh +``` + +**Windows:** +```bash +scripts\test.bat +``` + +Both scripts run: +1. `go vet ./...` — static analysis for common errors and suspicious code patterns +2. `go test -race ./...` — tests with race condition detection enabled + +### Manual test commands + +Run all tests: +```bash +go test ./... +``` + +Run all tests with race detection: +```bash +go test -race ./... +``` + +Run tests with verbose output: +```bash +go test -v ./... +``` + +Run a specific test by name: +```bash +go test -run TestRunJobWritesLogFile ./src/core +``` + +Run tests with code coverage: +```bash +go test -cover ./src/core +go test -coverprofile=coverage.out ./src/core +go tool cover -html=coverage.out +``` + +--- + ## Test Files Overview ### store_test.go @@ -107,43 +158,6 @@ Tests Linux autostart entry creation via XDG Desktop Entry files. --- -## Running Tests - -### Run all tests in the package -```bash -cd D:\Local\Git\gosentry -go test ./src/core -``` - -### Run tests with verbose output -```bash -go test -v ./src/core -``` - -### Run specific test by name -```bash -go test -run TestRunJobWritesLogFile ./src/core -``` - -### Run Windows-only tests (on Windows) -```bash -go test -v ./src/core # Windows build tags are active -``` - -### Run Linux-only tests (on Linux) -```bash -go test -v ./src/core # Linux build tags are active -``` - -### Run with code coverage -```bash -go test -cover ./src/core -go test -coverprofile=coverage.out ./src/core -go tool cover -html=coverage.out -``` - ---- - ## Test Design Principles 1. **Isolation** — Tests use `t.TempDir()` for file operations and `t.Setenv()` for environment variables to avoid affecting system state. diff --git a/scripts/test.bat b/scripts/test.bat new file mode 100644 index 0000000..69f5c94 --- /dev/null +++ b/scripts/test.bat @@ -0,0 +1,23 @@ +@echo off +REM GoSentry test runner +REM Runs go vet and go test with race detection + +echo Running go vet... +go vet ./... +if errorlevel 1 ( + echo. + echo ✗ go vet failed + exit /b 1 +) + +echo. +echo Running go test with race detection... +go test -race ./... +if errorlevel 1 ( + echo. + echo ✗ go test failed + exit /b 1 +) + +echo. +echo ✓ All tests passed diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100644 index 0000000..33b381d --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# GoSentry test runner +# Runs go vet and go test with race detection + +set -e + +echo "Running go vet..." +go vet ./... + +echo "" +echo "Running go test with race detection..." +go test -race ./... + +echo "" +echo "✓ All tests passed"