Giter VIP home page Giter VIP logo

doctest's Introduction

Doctest for Emacs

Description

These are like a Python “doctest”, but for Emacs Lisp and with an Emacs twist. A doctest is a test written inside a docstring that looks like:

(defun plus (arg1 arg2)
  "Return sum of ARG1 and ARG2.
>> (plus 1 1)
=> 2
>> (plus (plus 5 3) 2)  ; with nesting
=> 10
>> (format \"%s\" (plus 1 2))
=> \"3\""
  (+ arg1 arg2))

There are benefits:

  • It’s a clean way to test elisp code without any heavy dependencies
  • It encourages functions that are pure or at least side-effect-free
  • Your unit tests turn into documentation that your users can read!

Usage

  • Use M-x doctest to run doctests on an entire buffer.
  • Use M-x doctest-here to run the doctest on the current line.
  • Use M-x doctest-defun to run the current defun’s doctests.

Related

  • Python doctest, the original
  • Elixir supports doctests
  • I copied the use of >> and => to mark input and output from Ruby doctest; prefixing output with => is useful because checkdoc complains if lines start with an opening parentheses, which will happen often in elisp code.

doctest's People

Contributors

ag91 avatar riscy avatar doublep avatar purcell avatar

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.