-
Notifications
You must be signed in to change notification settings - Fork 58
Add testing infrastructure for slang #272
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1568dc6
Add .clang-format and update .gitignore
fischeti e7d4514
tests: Add pickle testing repo
fischeti 6956781
bender-slang: Add unit and integration tests
fischeti 914e9a2
bender-slang: Add `.clangd` file for IDE support
fischeti 64e2b46
ci: Run on PRs to non-main branches
fischeti 0fe1418
bender-slang(build): Remove unnecessary if branch
fischeti af93ecb
tests: Remove pickle tests from `cli_regression`
fischeti 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 hidden or 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,18 @@ | ||
| --- | ||
| Language: Cpp | ||
| BasedOnStyle: LLVM | ||
|
|
||
| # 4 spaces everywhere | ||
| IndentWidth: 4 | ||
| TabWidth: 4 | ||
| UseTab: Never | ||
| ContinuationIndentWidth: 4 | ||
|
|
||
| # Modern C++ style | ||
| Standard: c++20 | ||
| ColumnLimit: 120 | ||
| PointerAlignment: Left | ||
|
|
||
| # Organize includes | ||
| SortIncludes: true | ||
| IncludeBlocks: Regroup |
This file contains hidden or 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,15 @@ | ||
| If: | ||
| PathMatch: (^|.*/)crates/bender-slang/cpp/.*\.(h|hpp|hh|c|cc|cpp|cxx)$ | ||
| CompileFlags: | ||
| Add: | ||
| - -std=c++20 | ||
| - -fno-cxx-modules | ||
| - -I. | ||
| - -I../../../crates | ||
| - -I../vendor/slang/include | ||
| - -I../vendor/slang/external | ||
| - -I../../../target/slang-generated-include | ||
| - -I../../../target/cxxbridge | ||
| - -DSLANG_USE_MIMALLOC=1 | ||
| - -DSLANG_USE_THREADS=1 | ||
| - -DSLANG_BOOST_SINGLE_HEADER=1 |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ on: | |
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| branches: [master] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
|
|
||
This file contains hidden or 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,6 +1,9 @@ | ||
| .* | ||
| !/.ci/ | ||
| !.git* | ||
| !.travis.yml | ||
| /target | ||
| /tests/tmp | ||
| # Cargo build files | ||
| target | ||
|
|
||
| # Temporary test files | ||
| tests/**/tmp | ||
| tests/**/.bender | ||
|
|
||
| # clangd | ||
| .cache/clangd |
This file contains hidden or 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 hidden or 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 hidden or 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,96 @@ | ||
| use std::path::PathBuf; | ||
|
|
||
| fn fixture_path(rel: &str) -> String { | ||
| PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| .join("../..") | ||
| .join("tests/pickle") | ||
| .join(rel) | ||
| .canonicalize() | ||
| .expect("valid fixture path") | ||
| .to_string_lossy() | ||
| .into_owned() | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_valid_file_succeeds() { | ||
| let mut session = bender_slang::SlangSession::new(); | ||
| let files = vec![fixture_path("src/top.sv")]; | ||
| let includes = vec![fixture_path("include")]; | ||
| let defines = vec![]; | ||
| assert!(session.parse_group(&files, &includes, &defines).is_ok()); | ||
| assert_eq!(session.tree_count(), 1); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_invalid_file_returns_parse_error() { | ||
| let mut session = bender_slang::SlangSession::new(); | ||
| let files = vec![fixture_path("src/broken.sv")]; | ||
| let includes = vec![]; | ||
| let defines = vec![]; | ||
| let result = session.parse_group(&files, &includes, &defines); | ||
|
|
||
| match result { | ||
| Err(bender_slang::SlangError::ParseGroup { .. }) => {} | ||
| Err(other) => panic!("expected SlangError::ParseGroup, got {other}"), | ||
| Ok(_) => panic!("expected parse to fail"), | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn rewriter_build_from_trees_is_repeatable() { | ||
| let mut session = bender_slang::SlangSession::new(); | ||
| let files = vec![fixture_path("src/top.sv")]; | ||
| let includes = vec![fixture_path("include")]; | ||
| let defines = vec![]; | ||
| session | ||
| .parse_group(&files, &includes, &defines) | ||
| .expect("parse should succeed"); | ||
|
|
||
| let trees = session.all_trees().expect("tree collection should succeed"); | ||
| let mut rewriter_once = bender_slang::SyntaxTreeRewriter::new(); | ||
| rewriter_once.set_prefix("p_"); | ||
| rewriter_once.set_suffix("_s"); | ||
| let first_pass_trees: Vec<_> = trees | ||
| .iter() | ||
| .map(|t| rewriter_once.rewrite_declarations(t)) | ||
| .collect(); | ||
| let renamed_once = rewriter_once.rewrite_references( | ||
| first_pass_trees | ||
| .first() | ||
| .expect("one first-pass tree expected"), | ||
| ); | ||
| assert!( | ||
| renamed_once | ||
| .display(bender_slang::SlangPrintOpts { | ||
| expand_macros: false, | ||
| include_directives: true, | ||
| include_comments: true, | ||
| squash_newlines: false, | ||
| }) | ||
| .contains("module p_top_s (") | ||
| ); | ||
|
|
||
| // Rebuilding with the same trees should remain stable. | ||
| let mut rewriter_twice = bender_slang::SyntaxTreeRewriter::new(); | ||
| rewriter_twice.set_prefix("p_"); | ||
| rewriter_twice.set_suffix("_s"); | ||
| let first_pass_trees: Vec<_> = trees | ||
| .iter() | ||
| .map(|t| rewriter_twice.rewrite_declarations(t)) | ||
| .collect(); | ||
| let renamed_twice = rewriter_twice.rewrite_references( | ||
| first_pass_trees | ||
| .first() | ||
| .expect("one first-pass tree expected"), | ||
| ); | ||
| assert!( | ||
| renamed_twice | ||
| .display(bender_slang::SlangPrintOpts { | ||
| expand_macros: false, | ||
| include_directives: true, | ||
| include_comments: true, | ||
| squash_newlines: false, | ||
| }) | ||
| .contains("module p_top_s (") | ||
| ); | ||
| } |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.