-
Notifications
You must be signed in to change notification settings - Fork 13
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
No elmi #15
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d3aec28
add parser to detect exposed values
harrysarson ba6b277
drop dep on elmi on path
harrysarson fef3845
remove dbg
harrysarson 158922e
update cargo deps
harrysarson 3e4f061
use tree-sitter crate
harrysarson 4777137
tidy parser up slightly
harrysarson 7d91a36
fix parsing comments
harrysarson 29d1ed2
apply review feedback
harrysarson 2b942f1
remove todo
harrysarson d763fee
fmt
harrysarson 7b0340b
make regexes wrap for readability
harrysarson 9a00b4d
remove all reference of elmi
harrysarson e52f54b
merge with updated master
mpizenberg 008b2e8
update cargo lock
mpizenberg abbee2d
change imports in run.rs
mpizenberg 06ad318
merge with updated master
mpizenberg 13fad6f
Remove unused compilation step
mpizenberg 9852287
Clarify that module paths are absolute
mpizenberg 66a3d01
Remove unneeded clone
mpizenberg 737130e
Aesthetics changes in get_module_name
mpizenberg 12d18be
Replace regex to check valid module name
mpizenberg 36c3a10
Minor code tweaks
mpizenberg 1bad6ac
Parsing using tree-sitter queries
mpizenberg ff6cc30
Add query for all top level declarations
mpizenberg 3e45cca
Move the query approach to the bottom of the file
mpizenberg 77b762e
Small refactor of query approach
mpizenberg 794b4c7
Remove tree-walking approach
mpizenberg d7d3278
Remove build dependencies
mpizenberg addca30
Simplify code detecting tests
mpizenberg 0b2748d
Code reorganization
mpizenberg d7f90de
Remove unused dependency
mpizenberg e75734e
Update readme with tests detection explanation
mpizenberg e529933
Add a section about behavior differences in readme
mpizenberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "tree-sitter-elm"] | ||
path = tree-sitter-elm | ||
url = https://github.com/Razzeee/tree-sitter-elm |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let dir: PathBuf = ["tree-sitter-elm", "src"].iter().collect(); | ||
|
||
cc::Build::new() | ||
.include(&dir) | ||
.file(dir.join("parser.c")) | ||
.flag_if_supported("-Wno-unused-but-set-variable") | ||
.compile("tree-sitter-parser"); | ||
|
||
cc::Build::new() | ||
.cpp(true) | ||
.include(&dir) | ||
.file(dir.join("scanner.cc")) | ||
.compile("tree-sitter-scanner"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,37 @@ | ||
//! Basically a wrapper module for elmi-to-json for the time being. | ||
//! It reads the compiled .elmi files and extracts exposed tests. | ||
|
||
use miniserde::{json, Deserialize}; | ||
use std::collections::HashSet; | ||
use std::path::{Path, PathBuf}; | ||
use std::process::{Command, Stdio}; | ||
use std::fs; | ||
|
||
/// Use elmi-to-json as a binary to extract all exposed tests | ||
/// from compiled .elmi files. | ||
pub fn all_tests<P: AsRef<Path>>( | ||
work_dir: P, | ||
src_files: &HashSet<PathBuf>, | ||
use std::path::Path; | ||
|
||
/// Find all possible tests (all values) in test_files. | ||
pub fn all_tests( | ||
test_files: impl IntoIterator<Item = impl AsRef<Path>>, | ||
) -> Result<Vec<TestModule>, String> { | ||
let output = Command::new("elmi-to-json") | ||
.arg("--for-elm-test") | ||
.arg("--elm-version") | ||
.arg("0.19.1") | ||
// stdio config | ||
.current_dir(&work_dir) | ||
.stdin(Stdio::null()) | ||
.stdout(Stdio::piped()) | ||
.stderr(Stdio::inherit()) | ||
.output() | ||
.expect("command failed to start"); | ||
let str_output = std::str::from_utf8(&output.stdout) | ||
.map_err(|_| "Output of elmi-to-json is not valid UTF-8".to_string())?; | ||
let output: ElmiToJsonOutput = | ||
json::from_str(str_output).map_err(|_| "Deserialization error".to_string())?; | ||
Ok(output | ||
.test_modules | ||
test_files | ||
.into_iter() | ||
// Filter out modules with no test | ||
.filter(|m| !m.tests.is_empty()) | ||
// Filter out modules not in the list of src_files (must also be canonical) | ||
.filter(|m| { | ||
let path = | ||
work_dir.as_ref().join(&m.path).canonicalize().expect( | ||
"There was an issue when retrieving module paths from elmi-to-json output", | ||
); | ||
src_files.contains(&path) | ||
}) | ||
// No need to verify that module names are valid, elm 0.19.1 already verifies that. | ||
// No need to filter exposed since only exposed values are in elmi files. | ||
.collect()) | ||
} | ||
.map(|test_file| { | ||
let source = fs::read_to_string(&test_file).unwrap(); | ||
|
||
#[derive(Deserialize, Debug)] | ||
/// Struct mirroring the json result of elmi-to-json --for-elm-test. | ||
struct ElmiToJsonOutput { | ||
#[serde(rename = "testModules")] | ||
test_modules: Vec<TestModule>, | ||
let tree = { | ||
let mut parser = tree_sitter::Parser::new(); | ||
let language = super::parser::tree_sitter_elm(); | ||
parser.set_language(language).unwrap(); | ||
parser.parse(&source, None).unwrap() | ||
}; | ||
|
||
crate::parser::get_all_exposed_values(&tree, &source) | ||
.map(|tests| TestModule { | ||
path: test_file.as_ref().to_str().unwrap().to_string(), | ||
tests: tests.iter().map(|s| s.to_string()).collect(), | ||
}) | ||
.map_err(|s| s.to_string()) | ||
}) | ||
.collect() | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
/// Test modules as listed in the json result of elmi-to-json. | ||
pub struct TestModule { | ||
#[serde(rename = "moduleName")] | ||
pub module_name: String, | ||
pub path: String, | ||
pub tests: Vec<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of date comment?