-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
;;; eldev-doctest.el --- Elisp development tool -*- lexical-binding: t -*- | ||
|
||
;;; Copyright (C) 2024 Paul Pogonyshev | ||
|
||
;; This program is free software; you can redistribute it and/or | ||
;; modify it under the terms of the GNU General Public License as | ||
;; published by the Free Software Foundation, either version 3 of | ||
;; the License, or (at your option) any later version. | ||
|
||
;; This program is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
;; | ||
;; You should have received a copy of the GNU General Public License | ||
;; along with this program. If not, see https://www.gnu.org/licenses. | ||
|
||
;;; Code: | ||
|
||
(require 'eldev) | ||
|
||
|
||
(defvar doctest-message-level) | ||
(defvar doctest-after-every-test-functions) | ||
(defvar doctest-after-all-tests-hook) | ||
|
||
(declare-function doctest-files "doctest") | ||
(declare-function doctest-state "doctest") | ||
|
||
|
||
(defvar eldev--test-doctest-concise-expected nil) | ||
|
||
|
||
(defun eldev-test-doctest-preprocess-selectors (selectors) | ||
(when selectors | ||
(eldev-warn "Doctest currently doesn't support selectors; they will be ignored"))) | ||
|
||
(defun eldev-run-doctest-tests (files &optional environment) | ||
"Run Doctest tests in specified FILES." | ||
(when eldev-test-stop-on-unexpected | ||
(eldev-warn "Option `--stop-on-unexpected' (`-s') is not supported with Doctest framework")) | ||
;; Unlike with other testing frameworks, the feature here is not required by the test | ||
;; files: those files are the same as program's source. | ||
(eldev--require-external-feature 'doctest) | ||
(eldev--test-load-files files) | ||
(eldev-bind-from-environment environment (doctest-message-level eldev--test-doctest-concise-expected) | ||
(let ((doctest-after-every-test-functions doctest-after-every-test-functions) | ||
(doctest-after-all-tests-hook doctest-after-all-tests-hook)) | ||
(when eldev--test-doctest-concise-expected | ||
(push (lambda (params) | ||
(let ((state (doctest-state))) | ||
(eldev-test-runner-concise-tick (and (eq (cdr (assq 'result params)) 'failure) | ||
;; Only force a number if Doctest is going to print something. | ||
(eq doctest-message-level 'info)) | ||
(cdr (assq 'total state))))) | ||
doctest-after-every-test-functions) | ||
(push (lambda () | ||
(let* ((state (doctest-state)) | ||
(num-total (cdr (assq 'total state)))) | ||
(unless (= eldev--test-runner-concise-num-reported num-total) | ||
(eldev-test-runner-concise-tick t num-total)))) | ||
doctest-after-all-tests-hook)) | ||
(doctest-files files))) | ||
(let ((state (doctest-state))) | ||
(setf eldev-test-num-passed (+ eldev-test-num-passed (cdr (assq 'passed state))) | ||
eldev-test-num-failed (+ eldev-test-num-failed (cdr (assq 'failed state)))) | ||
;; Even if unsupported by the framework, at least update the variable so that we can | ||
;; stop before running further test types. | ||
(when eldev-test-stop-on-unexpected | ||
(setf eldev-test-stop-on-unexpected (- eldev-test-stop-on-unexpected (assq 'failed state)))))) | ||
|
||
|
||
(provide 'eldev-doctest) | ||
|
||
;;; eldev-doctest.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
;; -*- lexical-binding: t -*- | ||
|
||
(require 'test/common) | ||
|
||
|
||
(ert-deftest eldev-test-doctest-project-m-1 () | ||
;; Two tests, all pass. | ||
(eldev--test-run "project-m" ("test") | ||
(should (string-match-p "2 passed" stdout)) | ||
(should (string-match-p "0 failed" stdout)) | ||
(should (= exit-code 0)))) | ||
|
||
|
||
(provide 'test/integration/doctest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(setf eldev-test-framework 'doctest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(defun project-m-hello-to (whom) | ||
"Doctest me: | ||
>> (project-m-hello-to \"world\") | ||
=> \"Hello, world!\"" | ||
(format "Hello, %s!" whom)) | ||
|
||
(provide 'project-m-advanced) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
;;; project-m.el --- Simple test project with no dependencies that uses `doctest' -*- lexical-binding: t -*- | ||
|
||
;; Version: 1.0 | ||
;; Homepage: https://example.com/ | ||
;; Package-Requires: ((emacs "24")) | ||
|
||
(defun project-m-hello () | ||
"Doctest me: | ||
>> (project-m-hello) | ||
=> \"Hello\"" | ||
"Hello") | ||
|
||
(provide 'project-m) | ||
|
||
;;; project-m.el ends here |
9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suhail-singh, @ag91: It took kinda long, but now there is some support for
doctest
in Eldev. Unlike with other frameworks, its use must be declared explicitly (seetest/project-m/Eldev
), because there is now good way to autodetect it. If you can, please try this out and tell me what's missing, wrong or buggy.9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@doublep thank you for the update.
will there be an Eldev release in the coming days which would include this functionality?
9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, within next week or so. But it would be nice if you could evaluate the additions before the release, maybe something is badly missing. See instructions to upgrade Eldev to an unreleased version.
9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some areas of improvement based on limited testing:
It would help if the
doctest
summary noted, at the very least, that thepass / fail statistics related to
doctest
tests. Other test runners suchas
ert
don't do this, however, they note the name of the test that is beingexecuted. Even something as simple as
Running doctest tests
would help.A failing
doctest
should result in a non-zero exit code foreldev test
.This doesn't seem to happen, at least when the
eldev-test-framework
is setto
'(ert doctest)
.9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@doublep ^
9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suhail-singh:
I think point 1. is rather for @ag91 to improve in the library directly.
Point 2 is valid, I apparently forgot this. Fixed now in 822e0d4 (and a test added).
9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this only for non-interactive run, so a
message
in doctest-files should do the trick, no?9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ag91: I don't know, maybe would be better to just prepend "Doctest summary: " to the summary string in all cases? Currently it just looks a bit out-of-context, like "what is passed/failed, I forgot what I did three seconds ago?"
Or maybe @suhail-singh could clarify what he meant. (I think here you need @, otherwise notifications probably don't get sent).
9f5387f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ag91 yes, i think that would be sufficient