woboq / tr

Translation tools for rust
57 stars 9 forks source link

Panic with test modules in extrnal files #12

Closed vmiklos closed 1 year ago

vmiklos commented 1 year ago

Given the following project:

mkdir -p src/mymod

cat > Cargo.toml <<EOF
[package]
name = "t"
version = "0.1.0"
edition = "2021"
[dependencies]
EOF

cat > src/lib.rs <<EOF
mod mymod;
EOF

cat > src/mymod.rs <<EOF
mod tests;
EOF

touch src/mymod/tests.rs

cargo build handles this fine, but when running xtr:

~/git/tr/target/debug/xtr --keyword=tr --charset UTF-8 -o test.pot src/mymod.rs

Then the output I get is:

thread 'main' panicked at 'No file with module definition for `mod tests` in file "src/mymod.rs"', xtr/src/crate_visitor.rs:130:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Note that folding src/mymod/tests.rs into src/mymod.rs works around the problem.

I haven't really looked into the xtr code, but I'm not against trying to fix this myself if the problem is simple enough or I can get some code pointers. :-) Thanks.