• This repository has been archived on 04/Sep/2021
  • Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created over 4 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A testing library that turns your README into executable Clojure tests!

seancorfield.readme

I have archived this project, in favor of using lread/test-doc-blocks which is much more comprehensive and tests all documentation, not just the README.

A simple library that turns examples in your README.md file into tests and runs them!

This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository.

Latest stable release: 1.0.16

Usage

Add an alias to your ~/.clojure/deps.edn file (or ~/.config/clojure/deps.edn file):

    :readme {:extra-deps {seancorfield/readme {:mvn/version "1.0.16"}}
             :main-opts ["-m" "seancorfield.readme"]}

Then the most basic usage is:

clojure -M:readme

This turns README.md's examples into tests in src/readme.clj, loads and runs them, and then deletes that generated file (line numbers in failures should match line numbers in your original README.md file).

You can optionally provide a different file path for the readme and for the generated file:

clojure -M:readme test/seancorfield/readme_example.md src/generated_test.clj

Note: The output file path must be on your classpath so that the generated namespace can be require'd. The generated file will be deleted after running the tests (unless it cannot be require'd due to syntax errors, when it will be left in place for you to debug).

If your README.md file contains a REPL session (using a user=> prompt) such as:

```clojure
user=> some-expression
result-1
user=> another-expression
result-2
```

This will generate tests of the form:

(deftest readme-N ; N is the line number
  (is (= result-1 some-expression))
  (is (= result-2 another-expression)))

If your README.md file contains code blocks of the form:

```clojure
some-expression
another-expression
=> result
```

This will generate tests of the form:

(deftest readme-N ; N is the line number
  (is (= result (do some-expression another-expression))))

Any additional code, without user=> or =>, will be added to the generated test namespace as-is with no direct test. This allows setup code to be shown in the README.md file, followed by specific tests.

Each clojure code block will become a standalone test (if it contains user=> or =>). The tests may be executed in any order (by clojure.test/run-tests). Expressions that are not considered to be parts of any tests will be executed in order when the generated test namespace is loaded (by this readme library).

If you wish to add Clojure-formatted code to your README that is ignored by this library, use whitespace between the triple backtick and clojure, like this:

``` clojure
;; ignored by seancorfield/readme
(do-stuff 42)
```

Caveats

You cannot use ns (or in-ns) forms in these examples, because the generated tests are all assumed to be in a single namespace (derived from the generated test filename).

Printed output is not considered when running tests. If the REPL session in your readme file needs to show output, it is recommended to show it as comments like this, so that it will be ignored by the generated tests:

user=> (println (+ 1 2 3))
;; prints:
; 6
nil

Usage with Leiningen

You can add the following to either your ~/.lein/profiles.clj file or to the :profiles section of your project.clj file:

  :doc-test {:dependencies [[seancorfield/readme "1.0.16"]]
             :aliases {"doc-test" ["run" "-m" "seancorfield.readme"]}}

Then you can run lein with-profile doc-test doc-test.

[Thank you to @Akeboshiwind for this tip!]

Development

Run the tests:

$ clojure -X:test:runner

Build a deployable jar of this library:

$ clojure -X:jar

Install it locally:

$ clojure -X:install

Deploy it to Clojars -- needs CLOJARS_USERNAME and CLOJARS_PASSWORD environment variables:

$ clojure -X:deploy

License

Copyright © 2020 Sean Corfield, all rights reserved.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

More Repositories

1

honeysql

Turn Clojure data structures into SQL
Clojure
1,763
star
2

next-jdbc

A modern low-level Clojure wrapper for JDBC-based access to databases.
Clojure
752
star
3

dot-clojure

My .clojure/deps.edn file
Clojure
615
star
4

deps-new

Create new projects for the Clojure CLI / deps.edn
Clojure
353
star
5

usermanager-example

A little demo web app in Clojure, using Component, Ring, Compojure, Selmer (and a database)
Clojure
338
star
6

build-clj

Common build tasks abstracted into a library.
Clojure
155
star
7

vscode-calva-setup

My VS Code / Calva / Portal / Joyride setup
Clojure
93
star
8

om-sente

Playground to create Om + Sente test app
JavaScript
46
star
9

jsql

Basic DSL for generating SQL/DDL, formerly java.jdbc.sql and java.jdbc.ddl
Clojure
43
star
10

boot-tools-deps

A Boot task (deps) that wraps tools.deps(.alpha) to read deps.edn files
Clojure
39
star
11

engine

A Clojure library to implement a query -> logic -> updates workflow, to separate persistence updates from business logic, to improve testing etc.
Clojure
22
star
12

clj-soap

Fork of https://bitbucket.org/taka2ru/clj-soap updated to latest Clojure version
Clojure
21
star
13

lein-fregec

A Leiningen plugin to compile Frege (http://www.frege-lang.org) code.
Clojure
20
star
14

atom-chlorine-setup

My Atom / Chlorine setup
Clojure
17
star
15

polylith-external-test-runner

An external (subprocess) test runner for Polylith
Clojure
13
star
16

socket-rebl

A Socket REPL that also submits forms to Cognitect's REBL
Clojure
13
star
17

next.jdbc.xt

Experimental extension of next.jdbc to work with XTDB 2.0 (snapshots)
Clojure
12
star
18

ring-cfml

A version of Ring (Clojure) for CFML
ColdFusion
12
star
19

logging4j2

A Clojure wrapper for log4j2
Clojure
11
star
20

java-clojure-example

Trivial example to show using Java from Clojure in deps.edn project
Clojure
9
star
21

datamapper

A couple of CFCs from the World Singles data mapper to show how we wrap Clojure (vectors of) hashmaps to present a thin OO veneer to our CFML code.
ColdFusion
8
star
22

liquid-setup

Configuration for the Liquid in-process Clojure editor
Clojure
7
star
23

boot-kotlinc

A Kotlin compilation task for Boot
Clojure
6
star
24

macro-day

Code examples I wrote during Amit Rathore's "A day with Clojure macros" training
Clojure
6
star
25

build-uber-log4j2-handler

A conflict handler for log4j2 plugins cache files for the tools.build uber task.
Clojure
6
star
26

edmund

Edmund is an Event-Driven Model micro-framework for CFML / ColdFusion
ColdFusion
5
star
27

avowal

Futures and Promises for modern CFML, inspired by my earlier cfconcurrency library
ColdFusion
3
star
28

datafy-nav-example

Examples of datafy and nav
Clojure
3
star
29

lein-fw1

A Leiningen plugin to create and manage FW/1 projects.
Clojure
3
star
30

cfml-interop

CFML/Clojure interop library extracted from World Singles code and open sourced!
Clojure
3
star
31

clojure-dining-car

A Categorized and Annotated Directory of Clojure Libraries
2
star
32

intro2fp

Code samples for Introduction to Functional Programming talk, cf.Objective() 2011
ColdFusion
2
star
33

cat-genetics

Utilities to help calculate TICA-specific color cat genetics etc
Clojure
2
star
34

clojure-lucee

A toy example of running CFML pages via Lucee as an embedded engine in a Clojure Ring application.
Clojure
2
star
35

lightstuff

Historical archive of Peter Bell's LightBase and LightGen utility framework/code
ColdFusion
2
star
36

orm-blog

A very simple blog/cms built in ColdFusion using Framework 1 and ORM.
ColdFusion
2
star
37

poly-classloader-bug

Repro for a potential classloader bug for poly test
Clojure
1
star
38

dojo-anthem

Team 1's code from the January 2013 San Francisco Clojure Dojo - to play the National Anthem
Clojure
1
star
39

cursive-expectations

Example of using Expectations with Cursive
Clojure
1
star
40

spd1

Introduction to Systematic Program Design Part 1 - some Clojure examples
Clojure
1
star
41

ordered-subset

Clojure
1
star
42

HUnitFrege

A port of HUnit from Haskell to Frege (WIP -- not even compiling yet!)
Frege
1
star
43

cfo2013

Code examples for my cf.Objective() 2013 presentations
ColdFusion
1
star
44

clojure-test

A place to discuss clojure.test concerns and possible enhancements
1
star
45

boot-localrepo

Boot tasks that wrap lein-localrepo functionality
Clojure
1
star
46

seancorfield.github.io

An Architect's View - my blog and personal web site
HTML
1
star
47

polylith-issue146

Repro for the setup-fn problem with the issue-146 branch
Clojure
1
star
48

WeeklyWrongChallenge

The weekly challenge repo for WPW
Clojure
1
star
49

ring-async-bug

SSCCE of Ring with async on Jetty that fails with thread death
Clojure
1
star
50

avaus-tv

Simulation of Avaus-TV prize draw, in Clojure
Clojure
1
star
51

hello-compojure

The Compojure template, but without lein-ring
Clojure
1
star
52

cfbloggers

Clojure scratch code to parse and analyze the feeds at coldfusionbloggers.org
Clojure
1
star
53

boxlang-clojure

An example of calling Clojure code from BoxLang
Clojure
1
star