Code Monkey home page Code Monkey logo

gleeunit's Introduction

gleeunit

Gleam bindings to the Erlang EUnit test framework.

A custom test runner is included for when compiled to JavaScript running on either NodeJS or Deno.

Documentation is available on HexDocs.

Usage

Add this package to your Gleam project.

gleam add gleeunit --dev

And then call the gleeunit.main function from your test main function.

// In test/yourapp_test.gleam
import gleeunit

pub fn main() {
  gleeunit.main()
}

Now any public function with a name ending in _test in the test directory will be found and run as a test.

pub fn the_universe_test() {
  let assert 1 = 1
}

Run the tests by entering gleam test in the command line.

Deno

If using the Deno JavaScript runtime, you will need to add the following to your gleam.toml.

[javascript.deno]
allow_read = [
  "gleam.toml",
  "test",
  "build",
]

gleeunit's People

Contributors

ajstrand avatar barksten avatar bjufre avatar darky avatar fabjan avatar giacomocavalieri avatar inoas avatar katafrakt avatar lpil avatar massivefermion avatar nathanjohnson320 avatar nicklasxyz avatar tynanbe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gleeunit's Issues

Backport some Glacier changes into Gleeunit

Before opening a PR and doing a lot of work I wanted to know if you are up for (me) backporting some changes from Glacier to Gleeunit.

The changes in question would be about making gleeunit take a list of module names gleeunit -- test/foo_test.gleam test/foo2_unit.gleam and formatting outputs.

The changes are here mostly https://github.com/inoas/glacier/tree/main/src in the files still named gleeunit*.

My goal would be to remove all the inlined copies fo gleeunit out of glacier again and just make glacier depend on gleeunit.

How to run only one test

Hi

I would like to run only a subset of tests.
e.g. one test or all tests for one module

With rebar3 it was something like rebar3 eunit --module=day04_test

It is possible with gleam test? How?

Thanks

Mix resolution problem

Dependencies have diverged:

  • gleam_stdlib (Hex package)
    the dependency gleam_stdlib in mix.exs is overriding a child dependency:

    In mix.exs:
    {:gleam_stdlib, "~> 0.24", [env: :prod, repo: "hexpm", hex: "gleam_stdlib", compile: "gleam build", app: false]}

    In deps/gleeunit/mix.exs:
    {:gleam_stdlib, "~> 0.19", [env: :prod, hex: "gleam_stdlib", repo: "hexpm", optional: false]}

    Ensure they match or specify one of the above in your deps and set "override: true"
    ** (Mix) Can't continue due to errors on dependencies

Cannot build on Gleam 0.32

Gleeunit reports to be compatible with Gleam 0.32, but it cannot be built on Gleam 0.32:

error: Syntax error
   ┌─ /Users/nicd/svn/glentities/build/packages/gleeunit/src/gleeunit/should.gleam:20:22
   │
20 │       panic as string.concat([
   │                      ^ I was not expecting this.

Expected one of:
a string

JS: test failure shows line number within function within should.gleam, not within failed test function

When testing javascript code, a failing test function is correctly identified within the error message, but the indicated line number is a line number within should.gleam, not within the test code. This makes it difficult, if not impossible to tell which line within a test function is the failing test, when multiple "should" calls are made within a single test function.

Of course, one solution is to make only one "should" call within each test function, but that's not always feasible. When it's not feasible, determining exactly which line is causing the failure can be a bit frustrating, increasing debugging difficulty

The reason that this occurs is because the "should" functions makes use of panic, but during JS transpilation, that translates to constructing errors with the line number of the panic, which is in the "should" function, not within the test function. (I don't know if this is also the case for Erlang.)

Separate halt logic

gleeunit calls erlang:halt/1 to return an exit code for use in CI/CD pipelines.

I am currently using the scaffolded foo_test.gleamfile module to start and stop the external systems. However, cleanup code after gleeunit.main() doesn't run because of the halt. Could have the scaffolded code look like t

gleeunit.main() |> gleeunit.halt()

This would allow folks to break the two apart, adding cleanup code between two functions before a halt.

Error formatting breaks Unicode characters

  1. Create new project
  2. Edit autogenerated test to:
pub fn hello_world_test() {
  "ööö"
  |> should.equal("äää")
}
  1. Run gleam test

Output:

  1) issue_test_test.hello_world_test: module 'issue_test_test'
     Values were not equal
     expected: "äää"
          got: "ööö"

Expected output:

  1) issue_test_test.hello_world_test: module 'issue_test_test'
     Values were not equal
     expected: "äää"
          got: "ööö"

I suspect the reason is somewhere in the interplay of string.inspect and the gleeunit formatters, but I could not pinpoint it.

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.