Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mainshayne233/markdown_test
Test the Elixir code in your markdown files!
https://github.com/mainshayne233/markdown_test
Last synced: 8 days ago
JSON representation
Test the Elixir code in your markdown files!
- Host: GitHub
- URL: https://github.com/mainshayne233/markdown_test
- Owner: MainShayne233
- Created: 2019-11-13T23:37:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-05T17:48:17.000Z (almost 5 years ago)
- Last Synced: 2024-11-01T09:34:19.608Z (18 days ago)
- Language: Elixir
- Homepage:
- Size: 18.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MarkdownTest
[![Build Status](https://secure.travis-ci.org/MainShayne233/markdown_test.svg?branch=master "Build Status")](http://travis-ci.org/MainShayne233/markdown_test)
[![Coverage Status](https://coveralls.io/repos/github/MainShayne233/markdown_test/badge.svg?branch=master)](https://coveralls.io/github/MainShayne233/markdown_test?branch=master)
[![Hex Version](http://img.shields.io/hexpm/v/markdown_test.svg?style=flat)](https://hex.pm/packages/markdown_test)Test the Elixir code in your markdown!
## Usage
Add `:markdown_test` as a dependency in your `mix.exs` file:
```elixir
# mix.exsdefp deps do
[
{:markdown_test, "0.1.2", only: :test}
]
end
```In any test module, `use MarkdownTest` to pull in the `test_markdown/1` macro and call it for your markdown file:
```elixir
defmodule MyLibraryTest do
use MarkdownTesttest_markdown("README.md")
end
```Then add some Elixir code to test in your markdown file.
The format roughly resembles that of a [`doctest`](https://elixir-lang.org/getting-started/mix-otp/docs-tests-and-with.html).
In order to be picked up, a code block must be between the following markdown comment tags:
``
...code
``.
### Examples
```elixir
iex> 1 + 2
3
```The expression and expected values can span multiple lines:
```elixir
iex> a = %{cool: :beans}
...> b = %{beans: :cool}
...> Map.merge(a, b)
%{
cool: :beans,
beans: :cool
}
```You can also include any setup code that needs to be run prior to testing the code:
```elixir
defmodule MyModule do
def add(x, y), do: x + y
endiex> MyModule.add(1, 2)
3
````markdown_test` will assert that the expression and the expected value match according to [Elixir's pattern matching](https://elixir-lang.org/getting-started/pattern-matching.html).
Therefore, you can write a test like this:
```elixir
defmodule MyModule do
def big_result do
{:ok, List.duplicate("hey", 1000)}
end
endiex> MyModule.big_result()
{:ok, ["hey" | _]}
```If you don't add any assertion code, `markdown_test` will just verify that the code snippet compiles, like:
```elixir
%{
this: %{
"should" => :compile
}
}
```