diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-04 23:35:07 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-04 23:35:07 -0600 |
| commit | 9d99ca0e41d0ccd6e8861ef6701da58c5b00a547 (patch) | |
| tree | 354ba854ed0d96fb70f2227bc3efecd8f1f415b7 /tests/test-flycheck-languagetool-setup.el | |
| parent | eda461086e94265b67ab5b21032e7ee23112ad87 (diff) | |
test: Add comprehensive test suite for LanguageTool grammar checking
Created complete test coverage for the LanguageTool integration:
Unit Tests (test-flycheck-languagetool-setup.el):
- 6 tests covering installation and configuration
- Verifies LanguageTool binary availability
- Checks wrapper script exists and is executable
- Validates wrapper script structure (shebang, imports)
- Tests error handling for missing arguments
- All tests pass ✓
Integration Tests (test-integration-grammar-checking.el):
- 9 tests covering end-to-end grammar checking workflow
- Tests wrapper script with real LanguageTool execution
- Validates output format (filename:line:column: message)
- Tests normal cases (error detection, formatting)
- Tests boundary cases (empty files, single word, multiple paragraphs)
- Tests error cases (nonexistent files, missing arguments)
- Uses real test fixtures with known grammar errors
- All tests pass ✓ (takes ~35 seconds due to LanguageTool execution)
Test Fixtures (tests/fixtures/grammar-*.txt):
- grammar-errors-basic.txt: Common errors (subject-verb, could of, etc.)
- grammar-errors-punctuation.txt: Punctuation and spacing errors
- grammar-correct.txt: Clean text with no errors
Testing Philosophy Applied:
- Focus on OUR code (wrapper script), not flycheck internals
- Trust external frameworks work correctly
- Test real integration (wrapper → LanguageTool → output)
- No mocking of domain logic, only external side-effects
- Clear test categories: Normal, Boundary, Error cases
- Comprehensive docstrings listing integrated components
- Deterministic tests using real fixtures
Usage:
make test-file FILE=test-flycheck-languagetool-setup.el
make test-file FILE=test-integration-grammar-checking.el
make test-integration # Includes grammar integration test
Tests automatically discovered by Makefile wildcards.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'tests/test-flycheck-languagetool-setup.el')
| -rw-r--r-- | tests/test-flycheck-languagetool-setup.el | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test-flycheck-languagetool-setup.el b/tests/test-flycheck-languagetool-setup.el new file mode 100644 index 00000000..a719e822 --- /dev/null +++ b/tests/test-flycheck-languagetool-setup.el @@ -0,0 +1,71 @@ +;;; test-flycheck-languagetool-setup.el --- Unit tests for LanguageTool setup -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests verifying LanguageTool installation and wrapper script setup. +;; Focus: Testing OUR code (wrapper script, file setup), not flycheck internals. +;; +;; We trust that flycheck works correctly (it's an external framework). +;; These tests verify: +;; - LanguageTool is installed and accessible +;; - Our wrapper script exists, is executable, and has correct structure +;; - Python 3 dependency is available +;; +;; Categories: Normal (installation checks), Boundary (script structure), Error (missing dependencies) + +;;; Code: + +(require 'ert) + +;; ----------------------------- Normal Cases ---------------------------------- + +(ert-deftest test-flycheck-languagetool-setup-normal-wrapper-exists () + "Test that languagetool-flycheck wrapper script exists." + (let ((wrapper-path (expand-file-name "~/.emacs.d/scripts/languagetool-flycheck"))) + (should (file-exists-p wrapper-path)))) + +(ert-deftest test-flycheck-languagetool-setup-normal-wrapper-executable () + "Test that languagetool-flycheck wrapper script is executable." + (let ((wrapper-path (expand-file-name "~/.emacs.d/scripts/languagetool-flycheck"))) + (should (file-executable-p wrapper-path)))) + +(ert-deftest test-flycheck-languagetool-setup-normal-languagetool-installed () + "Test that languagetool command is available in PATH." + (should (executable-find "languagetool"))) + +(ert-deftest test-flycheck-languagetool-setup-normal-python3-available () + "Test that python3 is available for wrapper script." + (should (executable-find "python3"))) + + +;; ----------------------------- Boundary Cases -------------------------------- + +(ert-deftest test-flycheck-languagetool-setup-boundary-wrapper-script-format () + "Test that wrapper script has correct shebang and structure." + (let ((wrapper-path (expand-file-name "~/.emacs.d/scripts/languagetool-flycheck"))) + (with-temp-buffer + (insert-file-contents wrapper-path) + (goto-char (point-min)) + ;; Check shebang + (should (looking-at "#!/usr/bin/env python3")) + ;; Check it contains required imports + (should (search-forward "import json" nil t)) + (should (search-forward "import subprocess" nil t))))) + +;; ----------------------------- Error Cases ----------------------------------- + +(ert-deftest test-flycheck-languagetool-setup-error-missing-file-argument () + "Test that wrapper script requires file argument. +When called without arguments, wrapper should exit with error." + (let* ((wrapper (expand-file-name "~/.emacs.d/scripts/languagetool-flycheck")) + (exit-code nil)) + (with-temp-buffer + (setq exit-code (call-process wrapper nil t nil)) + ;; Should exit with non-zero status when no file provided + (should-not (= 0 exit-code)) + ;; Should print usage message to stderr (captured in buffer) + (goto-char (point-min)) + (should (or (search-forward "Usage:" nil t) + (search-forward "FILE" nil t)))))) + +(provide 'test-flycheck-languagetool-setup) +;;; test-flycheck-languagetool-setup.el ends here |
