GithubHelp home page GithubHelp logo

Comments (5)

ag91 avatar ag91 commented on August 10, 2024

Thanks for reporting this with examples!
I don't have much experience in reporting signals source, do you have a reference I can look up?
I guess at least not dropping the ball at the first failing test could be easily achievable.

A note to myself, the command to reproduce in my settings

emacs --batch --eval "(progn (package-initialize) (require 'doctest) (doctest \"test.el\"))"

where test

(defun divide (a b)
  "
>> (/ 1 0)
=> 2


>> (divide 1 2)
=> 3

>> (divide 1 0)
=> 3"
  (/ a b))

from doctest.

ag91 avatar ag91 commented on August 10, 2024

with my latest change this improves a little bit. How does that sound @doublep ?

An example of trace:

Warning (emacs): Test cases in comments can cause byte-compile warnings, please add '(not docstrings) to `byte-compile-warnings'
35
58
80
0 passed, 3 failed

test.el#4: (/ 1 0 => 2 but got Failure evaluating input:

(/ 1 0
which caused:
(end-of-file)

test.el#8: (divide 1 2) => 3 but got 0test.el#11: (divide 1 0) => 3 but got Failure evaluating input:

(divide 1 0)
which caused:
(arith-error)

from doctest.

doublep avatar doublep commented on August 10, 2024

I don't have much experience in reporting signals source, do you have a reference I can look up?

You could study either ERT or Buttercup source code. They use Edebug functionality to find backtraces. Buttercup is probably more readable.

The largest difference to your quick hack is that they print signal backtrace, which is useful if the error is signalled not from the function in question, but from something it calls (with 10 nesting levels). Though you could argue that doctest is aimed at simple functions.

+           (evaluated-input (condition-case err
+                                (format "%S" (eval (car (read-from-string input))))
+                              (error
+                               (format "Failure evaluating input:\n\n%s\nwhich caused:\n%s\n\n" input err))))

At the very least the error handler should use t instead of error. Otherwise the condition-case form doesn't catch non-error signals, just try this:

>> (signal 'wtf nil)
=> nil

Error output also confusingly repeats test code twice.

from doctest.

ag91 avatar ag91 commented on August 10, 2024

thanks I will give a look at buttercup source once I have time.
This change should do for a minimal functionality though.
Happy to receive a PR for more advanced stuff meanwhile I (find the time to) study.

from doctest.

ag91 avatar ag91 commented on August 10, 2024

closing this as I consider the more advanced version something nice to have but not strictly necessary yet.

from doctest.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.