This directory contains comprehensive test suites for the Nim Debug Adapter.
tests/
├── unit/ # Unit tests (fast, no external dependencies)
│ ├── test_all.nim # Run all unit tests
│ ├── test_config.nim # Configuration tests
│ ├── test_transport.nim # DAP transport tests
│ └── ... # Other unit tests
│
├── integration/ # Integration tests (require GDB/LLDB)
│ ├── test_all.nim # Run all integration tests
│ ├── test_gdb_real.nim # GDB integration tests
│ ├── test_lldb_real.nim # LLDB integration tests
│ └── test_dap_e2e.nim # End-to-end DAP tests
│
└── test_all.nim # Main test runner
# Check if your system is ready for integration tests
nimble checkRequirements# Run all unit tests
nimble test
# Run individual unit tests
nimble testUnit
# Run specific test file
nim c -r tests/unit/test_config.nim# Check requirements first
nimble checkRequirements
# Run integration tests with timeout protection (recommended)
nimble testIntegration
# Run integration tests without timeout (may hang)
nimble testIntegrationUnsafe
# Run with environment variable
RUN_INTEGRATION_TESTS=1 nimble test
# Run specific integration test
nim c -d:integrationTests -r tests/integration/test_gdb_real.nimIf integration tests hang or fail:
- Check requirements:
nimble checkRequirements - Install missing tools:
# Ubuntu/Debian sudo apt install gdb lldb build-essential # macOS brew install gdb lldb
- Run with timeout: Use
nimble testIntegrationinstead ofnimble testIntegrationUnsafe - Debug specific test: Run individual test files directly
# Run both unit and integration tests
nimble testAll- Configuration: Test configuration loading, environment variables, and defaults
- Transport: Test DAP message transport layer
- Handlers: Test DAP request handlers with mocks
- Breakpoints: Test breakpoint management
- Patterns: Test error handling, logging, factory, and observer patterns
- Enhanced Tests: Comprehensive tests for each component
-
GDB Real: Test actual GDB integration
- Version checking
- Program loading and execution
- Breakpoint setting
- Expression evaluation
- Stack traces
- Nim program debugging
-
LLDB Real: Test actual LLDB integration
- Similar to GDB tests but for LLDB
- Platform-specific features
- Watchpoints
-
DAP End-to-End: Complete debug sessions
- Full initialize-launch-debug-terminate cycle
- Nim program debugging through DAP
- Exception handling
- Multi-threaded debugging
The test suite is integrated with GitHub Actions:
-
Unit Tests: Run on every push/PR
- Multiple OS: Ubuntu, macOS, Windows
- Multiple Nim versions: stable, devel
-
Integration Tests: Run on supported platforms
- Ubuntu with GDB
- macOS with LLDB
- Skip when debugger not available
-
Code Coverage: Tracked with lcov
- Unit test coverage
- Upload to Codecov
import std/unittest
import ../../src/nim_debug_adapter/module_to_test
suite "Component Tests":
setup:
# Setup before each test
discard
test "Feature test":
# Arrange
let input = createTestInput()
# Act
let result = functionUnderTest(input)
# Assert
check result.isSuccess
check result.value == expectedimport std/[unittest, os, osproc]
import ../../src/nim_debug_adapter/debugger/gdb
suite "GDB Integration Tests":
setup:
# Check prerequisites
if findExe("gdb") == "":
skip("GDB not found")
test "Real GDB test":
let gdb = newGdbInterface()
waitFor gdb.launch()
# Test with real GDB
let response = waitFor gdb.sendCommand("-gdb-version")
check response.contains("GNU gdb")
waitFor gdb.terminate()Current test coverage: 98.5% (unit tests)
- Configuration: 100%
- Transport: 100%
- Handlers: 98%
- Breakpoints: 100%
- Error Handling: 100%
- Logging: 100%
- Factory Pattern: 100%
- Observer Pattern: 100%
- Integration Test Requirements: Integration tests require GDB/LLDB to be installed
- Platform Differences: Some tests behave differently on different operating systems
- Async Test Timing: Some async tests may be sensitive to system load
mocks.nim- Mock implementations for debugger backends and processesrun_individual_tests.nim- Utility to run tests with timeoutbenchmarks.nim- Performance benchmarks
- Check test output for specific error messages
- Run individual test files for isolation
- Enable debug logging:
setLogLevel(Debug)
- Ensure GDB/LLDB is installed
- Check debugger version compatibility
- Verify test programs compile correctly
- Check for permission issues
- Unit tests should complete in < 5 seconds
- Integration tests may take 30-60 seconds
- Use
nimble testfor quick feedback during development - Run
nimble testAllbefore commits