Skip to content

Commit

Permalink
Add proc-macro-server test
Browse files Browse the repository at this point in the history
  • Loading branch information
DelevoXDG committed Dec 10, 2024
1 parent 64f362e commit 981d3df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ jobs:
run: |
cargo test -p scarb --test build_cairo_plugin compile_with_prebuilt_plugins -- --exact
cargo test -p scarb --test build_cairo_plugin compile_with_invalid_prebuilt_plugins -- --exact
cargo test -p scarb --test proc_macro_server load_prebuilt_proc_macros -- --exact
31 changes: 30 additions & 1 deletion scarb/tests/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use scarb_proc_macro_server_types::methods::expand::ExpandInlineMacroParams;
use scarb_test_support::cairo_plugin_project_builder::CairoPluginProjectBuilder;
use scarb_test_support::proc_macro_server::ProcMacroClient;
use scarb_test_support::proc_macro_server::SIMPLE_MACROS;
use scarb_test_support::project_builder::ProjectBuilder;
use scarb_test_support::project_builder::{Dep, DepBuilder, ProjectBuilder};

#[test]
fn defined_macros() {
Expand Down Expand Up @@ -171,3 +171,32 @@ fn expand_inline() {
TokenStream::new("struct A { field: 25 , other_field: macro_call!(12)}".to_string())
);
}

#[test]
fn load_prebuilt_proc_macros() {
let t = TempDir::new().unwrap();

let project = t.child("test_package");

ProjectBuilder::start()
.name("test_package")
.version("1.0.0")
.lib_cairo("")
.dep(
"proc_macro_example",
Dep.version("0.1.2").registry("https://scarbs.dev/"),
)
.build(&project);

let mut proc_macro_server = ProcMacroClient::new_without_cargo(&project);

let response = proc_macro_server
.request_and_wait::<ExpandInline>(ExpandInlineMacroParams {
name: "some".to_string(),
args: TokenStream::new("42".to_string()),
})
.unwrap();

assert_eq!(response.diagnostics, vec![]);
assert_eq!(response.token_stream, TokenStream::new("42".to_string()));
}

0 comments on commit 981d3df

Please sign in to comment.