Skip to content
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

add test that checks that colums are 0-indexed in proc-macro environment as well #372

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
- run: cargo test --no-default-features --test features -- --ignored make_sure_no_proc_macro # run the ignored test to make sure the `proc-macro` feature is disabled
- run: cargo test --features span-locations
- run: cargo test --manifest-path tests/ui/Cargo.toml
- run: cargo test --manifest-path tests/span/Cargo.toml
- name: RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
run: cargo test
env:
Expand Down
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() {}