diff options
-rw-r--r-- | doc/misc/ert.texi | 4 | ||||
-rw-r--r-- | lisp/emacs-lisp/ert.el | 123 |
2 files changed, 71 insertions, 56 deletions
diff --git a/doc/misc/ert.texi b/doc/misc/ert.texi index 6604829b2b3..0eb9cdf09f6 100644 --- a/doc/misc/ert.texi +++ b/doc/misc/ert.texi @@ -873,6 +873,10 @@ make @code{ert-test-erts-file} place point where @samp{|} is in the where the @samp{|} character is in the ``after'' form (and issue a test failure if that isn't the case). (This is used in all subsequent tests, unless overridden by a new @samp{Point-Char} spec.) + +@item Skip +If this is present and value is a form that evaluates to a +non-@code{nil} value, the test will be skipped. @end table If you need to use the literal line single line @samp{=-=} in a test diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 204ccf5858a..ca3e4c3765a 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -2679,65 +2679,76 @@ TRANSFORM will be called to get from before to after." (end-after (if (re-search-forward "^=-=-=\n" nil t) (match-beginning 0) (point-max))) + (skip (cdr (assq 'skip specs))) end-before start-after after after-point) - (goto-char end-after) - ;; We have a separate after section. - (if (re-search-backward "^=-=\n" start-before t) - (setq end-before (match-beginning 0) - start-after (match-end 0)) - (setq end-before end-after - start-after start-before)) - ;; Update persistent specs. - (when-let ((point-char (assq 'point-char specs))) - (setq gen-specs - (map-insert gen-specs 'point-char (cdr point-char)))) - (when-let ((code (cdr (assq 'code specs)))) - (setq gen-specs - (map-insert gen-specs 'code (car (read-from-string code))))) - ;; Get the "after" strings. - (with-temp-buffer - (insert-buffer-substring file-buffer start-after end-after) - (ert--erts-unquote) - ;; Remove the newline at the end of the buffer. - (when-let ((no-newline (cdr (assq 'no-after-newline specs)))) - (goto-char (point-min)) - (when (re-search-forward "\n\\'" nil t) - (delete-region (match-beginning 0) (match-end 0)))) - ;; Get the expected "after" point. - (when-let ((point-char (cdr (assq 'point-char gen-specs)))) - (goto-char (point-min)) - (when (search-forward point-char nil t) - (delete-region (match-beginning 0) (match-end 0)) - (setq after-point (point)))) - (setq after (buffer-string))) - ;; Do the test. - (with-temp-buffer - (insert-buffer-substring file-buffer start-before end-before) - (ert--erts-unquote) - ;; Remove the newline at the end of the buffer. - (when-let ((no-newline (cdr (assq 'no-before-newline specs)))) + (unless name + (error "No name for test case")) + (if (and skip + (eval (car (read-from-string skip)))) + ;; Skipping this test. + () + ;; Do the test. + (goto-char end-after) + ;; We have a separate after section. + (if (re-search-backward "^=-=\n" start-before t) + (setq end-before (match-beginning 0) + start-after (match-end 0)) + (setq end-before end-after + start-after start-before)) + ;; Update persistent specs. + (when-let ((point-char (assq 'point-char specs))) + (setq gen-specs + (map-insert gen-specs 'point-char (cdr point-char)))) + (when-let ((code (cdr (assq 'code specs)))) + (setq gen-specs + (map-insert gen-specs 'code (car (read-from-string code))))) + ;; Get the "after" strings. + (with-temp-buffer + (insert-buffer-substring file-buffer start-after end-after) + (ert--erts-unquote) + ;; Remove the newline at the end of the buffer. + (when-let ((no-newline (cdr (assq 'no-after-newline specs)))) + (goto-char (point-min)) + (when (re-search-forward "\n\\'" nil t) + (delete-region (match-beginning 0) (match-end 0)))) + ;; Get the expected "after" point. + (when-let ((point-char (cdr (assq 'point-char gen-specs)))) + (goto-char (point-min)) + (when (search-forward point-char nil t) + (delete-region (match-beginning 0) (match-end 0)) + (setq after-point (point)))) + (setq after (buffer-string))) + ;; Do the test. + (with-temp-buffer + (insert-buffer-substring file-buffer start-before end-before) + (ert--erts-unquote) + ;; Remove the newline at the end of the buffer. + (when-let ((no-newline (cdr (assq 'no-before-newline specs)))) + (goto-char (point-min)) + (when (re-search-forward "\n\\'" nil t) + (delete-region (match-beginning 0) (match-end 0)))) (goto-char (point-min)) - (when (re-search-forward "\n\\'" nil t) - (delete-region (match-beginning 0) (match-end 0)))) - (goto-char (point-min)) - ;; Place point in the specified place. - (when-let ((point-char (cdr (assq 'point-char gen-specs)))) - (when (search-forward point-char nil t) - (delete-region (match-beginning 0) (match-end 0)))) - (funcall (cdr (assq 'code gen-specs))) - (unless (equal (buffer-string) after) - (ert-fail (list (format "Mismatch in test \"%s\", file %s" - name file) - (buffer-string) - after))) - (when (and after-point - (not (= after-point (point)))) - (ert-fail (list (format "Point wrong in test \"%s\", expected point %d, actual %d, file %s" - name - after-point (point) - file) - (buffer-string)))))))))) + ;; Place point in the specified place. + (when-let ((point-char (cdr (assq 'point-char gen-specs)))) + (when (search-forward point-char nil t) + (delete-region (match-beginning 0) (match-end 0)))) + (let ((code (cdr (assq 'code gen-specs)))) + (unless code + (error "No code to run the transform")) + (funcall code)) + (unless (equal (buffer-string) after) + (ert-fail (list (format "Mismatch in test \"%s\", file %s" + name file) + (buffer-string) + after))) + (when (and after-point + (not (= after-point (point)))) + (ert-fail (list (format "Point wrong in test \"%s\", expected point %d, actual %d, file %s" + name + after-point (point) + file) + (buffer-string))))))))))) (defun ert--erts-unquote () (goto-char (point-min)) |