T0.1: Add test scripts and documentation
Add scripts/test.sh and scripts/test.bat to run go vet and go test -race. Update docs/TESTS.md with test script usage and reorganized manual test commands. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+51
-37
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user