Skip to content

Commit e7ecd89

Browse files
committed
Add: State for issue eupn#71
This initial commit contains the state of play immediately after add the example crates: - test-project - test-procmacro-project Other than setting up the workspace references no changes to the example crates have been made. The integration test harness has not yet been implemented. Signed-off-by: Mark Van de Vyver <[email protected]>
1 parent c4151a5 commit e7ecd89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+416
-0
lines changed

test-workspace/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
members = [
3+
"wrkspc-dev",
4+
"wrkspc-macro",
5+
"wrkspc-test",
6+
"wrkspc",
7+
]

test-workspace/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# `test-project`
2+
3+
This is an example virtual-workspace that contains crates:
4+
5+
- `wrkspc`
6+
- `wrkspc-dev`
7+
- `wrkspc-macro`
8+
- `wrkspc-test`
9+
10+
Where each crate is:
11+
12+
- `wrkspc`: A "Hello world" style library (for release as a crate).
13+
- `wrkspc-dev`: A "Hello world" style library for development (not for release).
14+
- `wrkspc-macro`: The `test-promacro-project` adjusted to fit into the workspace plugin-test harness.
15+
- `wrkspc-test`: The `test-project` adjusted to fit into the workspace plugin-test harness.
16+
17+
Test harness for integration tests as plugins, is per the [Infinyon/Fluvio](https://www.infinyon.com/blog/2021/04/rust-custom-test-harness/) setup.

test-workspace/wrkspc-dev/Cargo.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "wrkspc-dev"
3+
version = "0.0.0"
4+
authors = ["Mark Van de Vyver <[email protected]>"]
5+
license = "Apache-2.0"
6+
edition = "2018"
7+
description = "A development crate in a virtual workspace example"
8+
homepage = "https://github.com/eupn/macrotest"
9+
repository = "https://github.com/eupn/macrotest"
10+
documentation = "https://docs.rs/macrotest"
11+
readme = "README.md"
12+
publish = false
13+
14+
[dependencies]
15+
wrkspc-macro = { path = "../wrkspc-macro" }

test-workspace/wrkspc-dev/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub use wrkspc_macro::*;
2+
3+
pub fn hello() {
4+
println!("Hello Developer World!")
5+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[test]
2+
fn wrkspc_test() {
3+
assert_eq!("equal", "equal")
4+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
**/*.rs.bk
3+
Cargo.lock
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "wrkspc-macro"
3+
version = "0.0.0"
4+
authors = ["eupn <[email protected]>"]
5+
edition = "2018"
6+
publish = false
7+
8+
[lib]
9+
proc-macro = true
10+
11+
[dependencies]
12+
quote = "1"
13+
proc-macro2 = "1.0"
14+
syn = "1.0"
15+
16+
[dev-dependencies]
17+
macrotest = { path = "../../" }
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
extern crate proc_macro;
2+
use proc_macro::TokenStream;
3+
4+
use quote::quote;
5+
use syn::{parse_macro_input, DeriveInput};
6+
7+
/// Example of [function-like procedural macro][1].
8+
///
9+
/// [1]: https://doc.rust-lang.org/reference/procedural-macros.html#function-like-procedural-macros
10+
#[proc_macro]
11+
pub fn my_macro(input: TokenStream) -> TokenStream {
12+
let input = parse_macro_input!(input as DeriveInput);
13+
14+
let tokens = quote! {
15+
#input
16+
17+
struct Hello;
18+
};
19+
20+
tokens.into()
21+
}
22+
23+
/// Example of user-defined [derive mode macro][1]
24+
///
25+
/// [1]: https://doc.rust-lang.org/reference/procedural-macros.html#derive-mode-macros
26+
#[proc_macro_derive(MyDerive)]
27+
pub fn my_derive(_input: TokenStream) -> TokenStream {
28+
// Emit test garbage
29+
let tokens = quote! {
30+
struct Hello;
31+
};
32+
33+
tokens.into()
34+
}
35+
36+
/// Example of user-defined [procedural macro attribute][1].
37+
///
38+
/// [1]: https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros
39+
#[proc_macro_attribute]
40+
pub fn my_attribute(_args: TokenStream, input: TokenStream) -> TokenStream {
41+
let input = parse_macro_input!(input as DeriveInput);
42+
43+
let tokens = quote! {
44+
#input
45+
46+
struct Hello;
47+
};
48+
49+
tokens.into()
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[macro_use]
2+
extern crate wrkspc_macro;
3+
struct Test;
4+
struct Hello;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[macro_use]
2+
extern crate wrkspc_macro;
3+
4+
#[my_attribute]
5+
struct Test;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[macro_use]
2+
extern crate wrkspc_macro;
3+
struct Test;
4+
struct Hello;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[macro_use]
2+
extern crate wrkspc_macro;
3+
4+
#[derive(MyDerive)]
5+
struct Test;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate wrkspc_macro;
3+
pub fn main() {
4+
struct Test;
5+
struct Hello;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate wrkspc_macro;
3+
4+
pub fn main() {
5+
my_macro! { struct Test; }
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[test]
2+
pub fn pass() {
3+
macrotest::expand("tests/expand/*.rs");
4+
}

test-workspace/wrkspc-test/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/target
2+
**/*.rs.bk

test-workspace/wrkspc-test/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "wrkspc-test"
3+
version = "0.0.0"
4+
edition = "2018"
5+
6+
[lib]
7+
8+
[features]
9+
default = []
10+
11+
test-feature = []
12+
13+
[dev-dependencies]
14+
macrotest = { path = "../../" }

test-workspace/wrkspc-test/src/lib.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#[macro_export]
2+
macro_rules! test_vec {
3+
() => {
4+
Vec::new()
5+
};
6+
( $( $x:expr ),+ ) => {
7+
{
8+
let mut temp_vec = Vec::new();
9+
$(
10+
temp_vec.push($x);
11+
)*
12+
temp_vec
13+
}
14+
};
15+
}
16+
17+
#[cfg(feature = "test-feature")]
18+
#[cfg_attr(feature = "test-feature", macro_export)]
19+
macro_rules! test_feature_vec {
20+
() => {
21+
Vec::new()
22+
};
23+
( $( $x:expr ),+ ) => {
24+
{
25+
let mut temp_vec = Vec::new();
26+
$(
27+
temp_vec.push($x);
28+
)*
29+
temp_vec
30+
}
31+
};
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
pub fn main() {
4+
Vec::new();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
pub fn main() {
4+
{
5+
let mut temp_vec = Vec::new();
6+
temp_vec.push(1);
7+
temp_vec.push(2);
8+
temp_vec.push(3);
9+
temp_vec
10+
};
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![1, 2, 3];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
pub fn main() {
4+
{
5+
let mut temp_vec = Vec::new();
6+
temp_vec.push(1);
7+
temp_vec
8+
};
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![1];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
pub fn main() {
4+
{
5+
let mut temp_vec = Vec::new();
6+
temp_vec.push(1);
7+
temp_vec.push(2);
8+
temp_vec
9+
};
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![1, 2];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extern crate std;
2+
#[macro_use]
3+
extern crate test_project;
4+
pub fn main() {
5+
{
6+
let mut temp_vec = Vec::new();
7+
temp_vec.push(1);
8+
temp_vec.push(2);
9+
temp_vec.push(3);
10+
temp_vec
11+
};
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![cfg(feature = "test-feature")]
2+
3+
#[macro_use]
4+
extern crate test_project;
5+
6+
pub fn main() {
7+
test_feature_vec![1, 2, 3];
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![1, 2, 3];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![1];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![1, 2];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![cfg(feature = "test-feature")]
2+
3+
#[macro_use]
4+
extern crate test_project;
5+
6+
pub fn main() {
7+
test_feature_vec![1, 2, 3];
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// The tests were interfering with each other when run in parallel.
2+
// This regression test module will ensure that parallel use case is handled.
3+
4+
#[test]
5+
pub fn parallel_1() {
6+
macrotest::expand("tests/expand/first.rs");
7+
}
8+
9+
#[test]
10+
pub fn parallel_2() {
11+
macrotest::expand("tests/expand/second.rs");
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
pub fn main() {
4+
Vec::new();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![];
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
pub fn main() {
4+
Vec::new();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_use]
2+
extern crate test_project;
3+
4+
pub fn main() {
5+
test_vec![];
6+
}

0 commit comments

Comments
 (0)