Skip to content

Commit

Permalink
add test that colums are 0-indexed in proc-macro environment as well
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelpilz committed Mar 25, 2023
1 parent 98645fd commit 3f6371e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nightly = []
doc-scrape-examples = false

[workspace]
members = ["benches/bench-libproc-macro", "tests/ui"]
members = ["benches/bench-libproc-macro", "tests/span", "tests/ui"]

[patch.crates-io]
# Our doc tests depend on quote which depends on proc-macro2. Without this line,
Expand Down
21 changes: 21 additions & 0 deletions tests/span/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "proc-macro2-span-test"
version = "0.0.0"
edition = "2018"
publish = false

[[test]]
name = "span-test"
path = "span.rs"

[dependencies]
proc-macro2 = { path = "../..", features = ["span-locations"] }

[dev-dependencies]
rustversion = "1.0"
proc-macro2-span-test = { path = "." }

[lib]
proc_macro = true
path = "span.rs"

23 changes: 23 additions & 0 deletions tests/span/span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Tests how Spans from `proc_macro` are treated in `proc_macro2`.
//!
//! In order to test this interaction, the test (or parts of it) have to be executed in a procmacro
//! environment. Instead of failing a test, `cargo test` fails to compile. This is a bit unfortunate,
//! but keeps things simpler.
//! This crate has a dev-dependency on itself, making it possible to call the proc-macro from the
//! tests.

#[cfg(not(test))]
#[proc_macro_attribute]
pub fn test_that_columns_are_0_indexed(
_attr: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let start = proc_macro2::Span::call_site().start();
assert_eq!(start.column, 0);
input
}

#[cfg(test)]
#[rustversion::nightly]
#[proc_macro2_span_test::test_that_columns_are_0_indexed]
fn _run_test_macro() {}

0 comments on commit 3f6371e

Please sign in to comment.