diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-04 16:32:16 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-04 16:32:16 -0500 |
| commit | 73c81a00a10766900318d86640249d1b54c6b351 (patch) | |
| tree | 793f9c858060591c34813af05e84c7a6a5442153 /tests/test-wttrin--extract-http-status.el | |
| parent | a77a7b86f45ae96ff1802ea6f8b87dafd46b17b0 (diff) | |
| download | emacs-wttrin-73c81a00a10766900318d86640249d1b54c6b351.tar.gz emacs-wttrin-73c81a00a10766900318d86640249d1b54c6b351.zip | |
feat: specific error messages for fetch failures
Add HTTP status code checking (wttrin--extract-http-status) and pass
error descriptions through the callback chain so users see "Location
not found (HTTP 404)" or "Network error — check your connection"
instead of the generic "Perhaps the location was misspelled?" for
every failure.
Also fix pre-existing bug where the condition-case error handler in
extract-response-body killed an unrelated buffer after unwind-protect
already cleaned up.
330 tests (was 307), all passing.
Diffstat (limited to 'tests/test-wttrin--extract-http-status.el')
| -rw-r--r-- | tests/test-wttrin--extract-http-status.el | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test-wttrin--extract-http-status.el b/tests/test-wttrin--extract-http-status.el new file mode 100644 index 0000000..4a714e2 --- /dev/null +++ b/tests/test-wttrin--extract-http-status.el @@ -0,0 +1,61 @@ +;;; test-wttrin--extract-http-status.el --- Tests for wttrin--extract-http-status -*- lexical-binding: t; -*- + +;; Copyright (C) 2025-2026 Craig Jennings + +;;; Commentary: + +;; Unit tests for wttrin--extract-http-status function. +;; Parses the HTTP status code from url-retrieve's response buffer. + +;;; Code: + +(require 'ert) +(require 'wttrin) +(require 'testutil-wttrin) + +;;; Normal Cases + +(ert-deftest test-wttrin--extract-http-status-normal-200 () + "Standard 200 OK response should return 200." + (with-temp-buffer + (insert "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nbody") + (should (= (wttrin--extract-http-status) 200)))) + +(ert-deftest test-wttrin--extract-http-status-normal-404 () + "404 Not Found response should return 404." + (with-temp-buffer + (insert "HTTP/1.1 404 Not Found\r\n\r\nNot found") + (should (= (wttrin--extract-http-status) 404)))) + +(ert-deftest test-wttrin--extract-http-status-normal-500 () + "500 Internal Server Error should return 500." + (with-temp-buffer + (insert "HTTP/1.1 500 Internal Server Error\r\n\r\nerror") + (should (= (wttrin--extract-http-status) 500)))) + +;;; Boundary Cases + +(ert-deftest test-wttrin--extract-http-status-boundary-no-status-line () + "Buffer with no HTTP status line should return nil." + (with-temp-buffer + (insert "just some text with no HTTP headers") + (should-not (wttrin--extract-http-status)))) + +(ert-deftest test-wttrin--extract-http-status-boundary-http2 () + "HTTP/2 responses use a different format but still have a status code." + (with-temp-buffer + (insert "HTTP/2 301 Moved Permanently\r\n\r\n") + (should (= (wttrin--extract-http-status) 301)))) + +(ert-deftest test-wttrin--extract-http-status-boundary-does-not-move-point () + "Parsing the status should not change point, so it doesn't interfere +with subsequent header/body parsing." + (with-temp-buffer + (insert "HTTP/1.1 200 OK\r\n\r\nbody") + (goto-char (point-min)) + (let ((pos-before (point))) + (wttrin--extract-http-status) + (should (= (point) pos-before))))) + +(provide 'test-wttrin--extract-http-status) +;;; test-wttrin--extract-http-status.el ends here |
