Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No elmi #15

Merged
merged 33 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d3aec28
add parser to detect exposed values
harrysarson Oct 30, 2020
ba6b277
drop dep on elmi on path
harrysarson Oct 31, 2020
fef3845
remove dbg
harrysarson Oct 31, 2020
158922e
update cargo deps
harrysarson Nov 22, 2020
3e4f061
use tree-sitter crate
harrysarson Nov 22, 2020
4777137
tidy parser up slightly
harrysarson Nov 22, 2020
7d91a36
fix parsing comments
harrysarson Nov 22, 2020
29d1ed2
apply review feedback
harrysarson Nov 22, 2020
2b942f1
remove todo
harrysarson Nov 22, 2020
d763fee
fmt
harrysarson Nov 22, 2020
7b0340b
make regexes wrap for readability
harrysarson Nov 22, 2020
9a00b4d
remove all reference of elmi
harrysarson Nov 22, 2020
e52f54b
merge with updated master
mpizenberg Nov 29, 2020
008b2e8
update cargo lock
mpizenberg Nov 29, 2020
abbee2d
change imports in run.rs
mpizenberg Nov 29, 2020
06ad318
merge with updated master
mpizenberg Dec 2, 2020
13fad6f
Remove unused compilation step
mpizenberg Dec 2, 2020
9852287
Clarify that module paths are absolute
mpizenberg Dec 2, 2020
66a3d01
Remove unneeded clone
mpizenberg Dec 2, 2020
737130e
Aesthetics changes in get_module_name
mpizenberg Dec 2, 2020
12d18be
Replace regex to check valid module name
mpizenberg Dec 3, 2020
36c3a10
Minor code tweaks
mpizenberg Dec 3, 2020
1bad6ac
Parsing using tree-sitter queries
mpizenberg Dec 4, 2020
ff6cc30
Add query for all top level declarations
mpizenberg Dec 4, 2020
3e45cca
Move the query approach to the bottom of the file
mpizenberg Dec 4, 2020
77b762e
Small refactor of query approach
mpizenberg Dec 4, 2020
794b4c7
Remove tree-walking approach
mpizenberg Dec 4, 2020
d7d3278
Remove build dependencies
mpizenberg Dec 7, 2020
addca30
Simplify code detecting tests
mpizenberg Dec 7, 2020
0b2748d
Code reorganization
mpizenberg Dec 7, 2020
d7f90de
Remove unused dependency
mpizenberg Dec 7, 2020
e75734e
Update readme with tests detection explanation
mpizenberg Dec 7, 2020
e529933
Add a section about behavior differences in readme
mpizenberg Dec 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ glob = "0.3.0"
miniserde = "0.1.13"
pathdiff = "0.2.0"
num_cpus = "1.13.0"
tree-sitter = "0.17.0"
regex = "1.4.1"
lazy_static = "1.4.0"
tree-sitter-elm = "4.3.4"

[dev-dependencies]
82 changes: 63 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ Attempt at a simpler alternative to node-test-runner for elm tests.
## Usage

Just replace `elm-test` by `elm-test-rs`.
Currently, you need to have elm 0.19.1, [elm-json][elm-json] and [elmi-to-json][elmi-to-json] installed.
Currently, you need to have elm 0.19.1, [elm-json][elm-json] installed.

[elm-json]: https://github.com/zwilias/elm-json
[elmi-to-json]: https://github.com/stoeffel/elmi-to-json


## Install
Expand Down Expand Up @@ -63,6 +62,29 @@ Additional features:
[progress-bar]: https://github.com/mpizenberg/elm-test-rs/pull/3


## Behavior Differences

The node-test-runner (elm-test) automatically adds a
`describe "ModuleName" [ yourTests ]` around your tests in a tests module.
With elm-test-rs no such wrapping is done.
You have to add an explicit `describe` if you want or need one.
This may be the case if you have the same tests in different tests modules,
resulting in a "duplicate test name" error.
In such cases, simply change

```elm
TestModule exposing (a, b, c)
```

into

```elm
TestModule exposing (tests)

tests = describe "TestModule" [ a, b, c ]
```


## Code architecture

The code of this project is split in three parts.
Expand All @@ -75,14 +97,6 @@ The code of this project is split in three parts.
3. An Elm package (pure, no debug logging) [mpizenberg/elm-test-runner][elm-test-runner]
exposing a main program for a runner and one for a reporter.

The supervisor and the runners communicate through child and parent worker messages.
The reporter is just loaded as a Node module by the supervisor.
Communication between the Elm and JS parts are done through ports, as usual.
More details about the supervisor, runner and reporter parts are available
in [mpizenberg/elm-test-runner][elm-test-runner].

[elm-test-runner]: elm

Rust was chosen for the first part since it is a very well fitted language
for systemish CLI programs and enables consise, fast and robust programs.
But any other language could replace this since it is completely independent
Expand All @@ -93,17 +107,48 @@ with inter-process-communication (IPC) going through named pipes.
The CLI program, if asked to run the tests, performs the following actions.

1. Generate the list of test modules and their file paths.
2. Generate a correct `elm.json` for the to-be-generated `Runner.elm`.
3. Compile all test files such that we know they are correct.
4. Find all tests.
5. Generate `Runner.elm` with a master test concatenating all found exposed tests.
6. Compile it into a JS file wrapped into a Node worker module.
7. Compile `Reporter.elm` into a Node module.
8. Generate and start the Node supervisor program.
1. Generate a correct `elm.json` for the to-be-generated `Runner.elm`.
1. Find all tests.
1. Generate `Runner.elm` with a master test concatenating all found exposed tests.
1. Compile it into a JS file wrapped into a Node worker module.
1. Compile `Reporter.elm` into a Node module.
1. Generate and start the Node supervisor program.

To find all tests, we perform a small trick, depending on kernel code (compiled elm code to JS).
First we parse all the tests modules to extract all potential `Test` exposed values.
This is done thanks to [tree-sitter-elm][tree-sitter-elm].
Then in the template file `Runner.elm` we embed code shaped like this.

```elm
check : a -> Maybe Test
check = ...

main : Program Flags Model Msg
main =
[ {{ potential_tests }} ]
|> List.filterMap check
|> Test.concat
|> ...
```

This template file gets compiled into a JavaScript file `Runner.elm.js`,
on which we perform the aforementioned kernel patch.
The patch consists in modifying all variants constructors of the `Test` type
to embed a marker, and modifying the `check` function to look for that marker.

Once all the JavaScript code has been generated, it is time to start
the supervisor Node file, which will organize tests runners.
The supervisor and the runners communicate through child and parent worker messages.
The reporter is just loaded as a Node module by the supervisor.
Communication between the Elm and JS parts are done through ports, as usual.
More details about the supervisor, runner and reporter parts are available
in [mpizenberg/elm-test-runner][elm-test-runner].

![architecture diagram][diagram]

[tree-sitter-elm]: https://github.com/Razzeee/tree-sitter-elm
[diagram]: https://mpizenberg.github.io/resources/elm-test-rs/elm-test-rs.png
[elm-test-runner]: elm


## Contributing
Expand Down Expand Up @@ -135,8 +180,7 @@ don't forget to `rustup update`.

As this is still a proof of concept, I cut a few corners to get things working.
For example, the generation of the `elm.json` for the tests uses directly
[zwilias/elm-json][elm-json] as a binary, and the detection of exposed tests is
done with [stoeffel/elmi-to-json][elmi-to-json] as in elm-test.
[zwilias/elm-json][elm-json] as a binary.

Eventually, it would be useful to extract the dependency solving algorithm from elm-json
into a crate of its own and to make it available offline if a suitable solution
Expand Down
62 changes: 0 additions & 62 deletions src/elmi.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod elm_json;
mod elmi;
mod help;
mod init;
mod install;
mod parser;
mod run;
mod utils;

Expand Down
Loading