diff options
| author | Stephen Gildea | 2025-01-27 10:41:01 -0800 |
|---|---|---|
| committer | Stephen Gildea | 2025-01-27 10:42:35 -0800 |
| commit | 2d386fc4490c8e61ed05384ec486ef0d5e7164b1 (patch) | |
| tree | b14800d60220ff16d1abd0bc94e7ecead670dde7 | |
| parent | 5eae7f5227c7789dea45cef26fec17c057024670 (diff) | |
| download | emacs-2d386fc4490c8e61ed05384ec486ef0d5e7164b1.tar.gz emacs-2d386fc4490c8e61ed05384ec486ef0d5e7164b1.zip | |
time-stamp-tests: Make macro-defined tests findable
* test/lisp/time-stamp-tests.el (define-formatz-tests): Use
'find-function-update-type-alist' to make defined tests findable.
(formatz-find-test-def-function): New test-finding function.
| -rw-r--r-- | test/lisp/time-stamp-tests.el | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el index 397e21f7bc7..eaca8d4d5ae 100644 --- a/test/lisp/time-stamp-tests.el +++ b/test/lisp/time-stamp-tests.el | |||
| @@ -1067,41 +1067,63 @@ the other expected results for hours greater than 99 with non-zero seconds." | |||
| 1067 | ;; We will modify this list, so start with a list consed at runtime. | 1067 | ;; We will modify this list, so start with a list consed at runtime. |
| 1068 | (let ((ert-test-list (list 'progn)) | 1068 | (let ((ert-test-list (list 'progn)) |
| 1069 | (common-description | 1069 | (common-description |
| 1070 | (concat "\nThis test expands from a call to" | 1070 | (concat "\nThis test is defined by a call to" |
| 1071 | " the macro `define-formatz-tests'.\n" | 1071 | " the macro `define-formatz-tests'."))) |
| 1072 | "To find the specific call, search the source file for \""))) | ||
| 1073 | (dolist (form-string form-strings ert-test-list) | 1072 | (dolist (form-string form-strings ert-test-list) |
| 1074 | (nconc | 1073 | (let ((test-name-hhmm |
| 1075 | ert-test-list | 1074 | (intern (concat "formatz-" form-string "-hhmm"))) |
| 1076 | (list | 1075 | (test-name-seconds |
| 1077 | `(ert-deftest ,(intern (concat "formatz-" form-string "-hhmm")) () | 1076 | (intern (concat "formatz-" form-string "-seconds"))) |
| 1078 | ,(concat "Test `time-stamp' format " form-string | 1077 | (test-name-threedigit |
| 1079 | " with whole hours and whole minutes.\n" | 1078 | (intern (concat "formatz-" form-string "-threedigit")))) |
| 1080 | common-description form-string "\".") | 1079 | (nconc |
| 1081 | (should (equal (formatz ,form-string (fz-make+zone 0)) | 1080 | ert-test-list |
| 1082 | ,(car hour-mod))) | 1081 | (list |
| 1083 | (formatz-hours-exact-helper ,form-string ',(cdr hour-mod)) | 1082 | `(find-function-update-type-alist |
| 1084 | (should (equal (formatz ,form-string (fz-make+zone 0 30)) | 1083 | ',test-name-hhmm 'ert--test 'formatz-find-test-def-function) |
| 1085 | ,(car mins-mod))) | 1084 | `(ert-deftest ,test-name-hhmm () |
| 1086 | (formatz-nonzero-minutes-helper ,form-string ',(cdr mins-mod))) | 1085 | ,(concat "Test `time-stamp' format " form-string |
| 1087 | `(ert-deftest ,(intern (concat "formatz-" form-string "-seconds")) () | 1086 | " with whole hours and whole minutes.\n" |
| 1088 | ,(concat "Test `time-stamp' format " form-string | 1087 | common-description) |
| 1089 | " with offsets that have non-zero seconds.\n" | 1088 | (should (equal (formatz ,form-string (fz-make+zone 0)) |
| 1090 | common-description form-string "\".") | 1089 | ,(car hour-mod))) |
| 1091 | (should (equal (formatz ,form-string (fz-make+zone 0 0 30)) | 1090 | (formatz-hours-exact-helper ,form-string ',(cdr hour-mod)) |
| 1092 | ,(car secs-mod))) | 1091 | (should (equal (formatz ,form-string (fz-make+zone 0 30)) |
| 1093 | (formatz-nonzero-seconds-helper ,form-string ',(cdr secs-mod))) | 1092 | ,(car mins-mod))) |
| 1094 | `(ert-deftest ,(intern (concat "formatz-" form-string "-threedigit")) () | 1093 | (formatz-nonzero-minutes-helper ,form-string ',(cdr mins-mod))) |
| 1095 | ,(concat "Test `time-stamp' format " form-string | 1094 | `(find-function-update-type-alist |
| 1096 | " with offsets of 100 hours or greater.\n" | 1095 | ',test-name-seconds 'ert--test 'formatz-find-test-def-function) |
| 1097 | common-description form-string "\".") | 1096 | `(ert-deftest ,test-name-seconds () |
| 1098 | (should (equal (formatz ,form-string (fz-make+zone 100)) | 1097 | ,(concat "Test `time-stamp' format " form-string |
| 1099 | ,(car big-mod))) | 1098 | " with offsets that have non-zero seconds.\n" |
| 1100 | (formatz-hours-big-helper ,form-string ',(cdr big-mod)) | 1099 | common-description) |
| 1101 | (should (equal (formatz ,form-string (fz-make+zone 100 0 30)) | 1100 | (should (equal (formatz ,form-string (fz-make+zone 0 0 30)) |
| 1102 | ,(car secbig-mod))) | 1101 | ,(car secs-mod))) |
| 1103 | (formatz-seconds-big-helper ,form-string ',(cdr secbig-mod))) | 1102 | (formatz-nonzero-seconds-helper ,form-string ',(cdr secs-mod))) |
| 1104 | ))))) | 1103 | `(find-function-update-type-alist |
| 1104 | ',test-name-threedigit 'ert--test 'formatz-find-test-def-function) | ||
| 1105 | `(ert-deftest ,test-name-threedigit () | ||
| 1106 | ,(concat "Test `time-stamp' format " form-string | ||
| 1107 | " with offsets of 100 hours or greater.\n" | ||
| 1108 | common-description) | ||
| 1109 | (should (equal (formatz ,form-string (fz-make+zone 100)) | ||
| 1110 | ,(car big-mod))) | ||
| 1111 | (formatz-hours-big-helper ,form-string ',(cdr big-mod)) | ||
| 1112 | (should (equal (formatz ,form-string (fz-make+zone 100 0 30)) | ||
| 1113 | ,(car secbig-mod))) | ||
| 1114 | (formatz-seconds-big-helper ,form-string ',(cdr secbig-mod))) | ||
| 1115 | )))))) | ||
| 1116 | |||
| 1117 | (defun formatz-find-test-def-function (test-name) | ||
| 1118 | "Search for the `define-formatz-tests' call defining test TEST-NAME. | ||
| 1119 | Return non-nil if the definition is found." | ||
| 1120 | (let* ((z-format (replace-regexp-in-string "\\`formatz-\\([^z]+z\\)-.*\\'" | ||
| 1121 | "\\1" | ||
| 1122 | (symbol-name test-name))) | ||
| 1123 | (regexp (concat "^(define-formatz-tests (" | ||
| 1124 | "\\(?:[^)]\\|;.*\n\\)*" | ||
| 1125 | "\"" (regexp-quote z-format) "\""))) | ||
| 1126 | (re-search-forward regexp nil t))) | ||
| 1105 | 1127 | ||
| 1106 | ;;;; The actual test cases for %z | 1128 | ;;;; The actual test cases for %z |
| 1107 | 1129 | ||