Skip to content

Commit

Permalink
Add #[track_caller] on helper functions in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 15, 2024
1 parent ef1ca20 commit af991ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use proc_macro2::{Ident, Span, TokenStream};
use std::str::FromStr;
use syn::Result;

#[track_caller]
fn parse(s: &str) -> Result<Ident> {
syn::parse2(TokenStream::from_str(s).unwrap())
}

#[track_caller]
fn new(s: &str) -> Ident {
Ident::new(s, Span::call_site())
}
Expand Down
8 changes: 8 additions & 0 deletions tests/test_lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use quote::ToTokens;
use std::str::FromStr;
use syn::{Lit, LitFloat, LitInt, LitStr};

#[track_caller]
fn lit(s: &str) -> Lit {
let mut tokens = TokenStream::from_str(s).unwrap().into_iter();
match tokens.next().unwrap() {
Expand All @@ -26,6 +27,7 @@ fn lit(s: &str) -> Lit {

#[test]
fn strings() {
#[track_caller]
fn test_string(s: &str, value: &str) {
match lit(s) {
Lit::Str(lit) => {
Expand Down Expand Up @@ -65,6 +67,7 @@ fn strings() {

#[test]
fn byte_strings() {
#[track_caller]
fn test_byte_string(s: &str, value: &[u8]) {
match lit(s) {
Lit::ByteStr(lit) => {
Expand Down Expand Up @@ -97,6 +100,7 @@ fn byte_strings() {

#[test]
fn bytes() {
#[track_caller]
fn test_byte(s: &str, value: u8) {
match lit(s) {
Lit::Byte(lit) => {
Expand All @@ -119,6 +123,7 @@ fn bytes() {

#[test]
fn chars() {
#[track_caller]
fn test_char(s: &str, value: char) {
match lit(s) {
Lit::Char(lit) => {
Expand All @@ -145,6 +150,7 @@ fn chars() {

#[test]
fn ints() {
#[track_caller]
fn test_int(s: &str, value: u64, suffix: &str) {
match lit(s) {
Lit::Int(lit) => {
Expand Down Expand Up @@ -185,6 +191,7 @@ fn ints() {

#[test]
fn floats() {
#[track_caller]
fn test_float(s: &str, value: f64, suffix: &str) {
match lit(s) {
Lit::Float(lit) => {
Expand Down Expand Up @@ -224,6 +231,7 @@ fn negative() {

#[test]
fn suffix() {
#[track_caller]
fn get_suffix(token: &str) -> String {
let lit = syn::parse_str::<Lit>(token).unwrap();
match lit {
Expand Down

0 comments on commit af991ca

Please sign in to comment.