You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I trying to replace macro_rules-based tests in my PR with generic-tests one. Everyseen works fine when I define test function in the test module (which is annotated with #[generic_tests::define]), but when I move my test into inner test::submod module, the compilation fails with impossible to find a trait.
I want to define my tests tree, including tests in the inner modules, like I do that for the ordinary tests framework, and then copy that tree for every set of template parameters. Is this possible?
The code that demonstrates problem:
use std::io::BufRead;//---------------------------------------------------------------// quick-xml like codetraitBufferedInput<'b,B>{fnread(&mutself,buf:B) -> &'b[u8];}/// Generic reader, copies data from reader into intermediate bufferimpl<'b,R:BufRead>BufferedInput<'b,&'bmutVec<u8>>forR{/// Read & Copy data from `self` into `buf`,/// return data that borrow from `buf`fnread(&mutself,buf:&'bmutVec<u8>) -> &'b[u8]{&buf[..]}}/// Borrowed reader, zero-copyimpl<'i>BufferedInput<'i,()>for&'i[u8]{/// Directly borrow data from `self`, do not copy,/// return data that borrow from `self`fnread(&mutself,_buf:()) -> &'i[u8]{self}}//---------------------------------------------------------------// My tests#[cfg(test)]#[generic_tests::define]mod test {/// Helper trait for `generic_tests` cratetraitStorage<'b>:Default{typeBuffer;/// Returns buffer for `BufferedInput::read`fnbuffer(&'bmutself) -> Self::Buffer;}impl<'b>Storage<'b>for(){typeBuffer = ();fnbuffer(&'bmutself){}}impl<'b>Storage<'b>forVec<u8>{typeBuffer = &'bmutVec<u8>;fnbuffer(&'bmutself) -> Self::Buffer{self}}#[test]fntest<S>()wherefor<'b>S:Storage<'b>,for<'b>&'b[u8]:crate::BufferedInput<'b, <SasStorage<'b>>::Buffer>,{letmut storage = S::default();
storage.buffer();}mod submod {usesuper::Storage;usecrate::BufferedInput;// This is failed to compile#[test]fntest<S>()wherefor<'b>S:Storage<'b>,for<'b>&'b[u8]:BufferedInput<'b, <SasStorage<'b>>::Buffer>,{letmut storage = S::default();
storage.buffer();}}/// Tests for reader that generates events that borrow from the provided buffer#[instantiate_tests(<Vec<u8>>)]mod buffered {}/// Tests for reader that generates events that borrow from the input#[instantiate_tests(<()>)]mod borrowed {}}
`cargo expand --tests` output
#![feature(prelude_import)]#[prelude_import]use std::prelude::rust_2021::*;#[macro_use]externcrate std;use std::io::BufRead;traitBufferedInput<'b,B>{fnread(&mutself,buf:B) -> &'b[u8];}/// Generic reader, copies data from reader into intermediate bufferimpl<'b,R:BufRead>BufferedInput<'b,&'bmutVec<u8>>forR{/// Read & Copy data from `self` into `buf`,/// return data that borrow from `buf`fnread(&mutself,buf:&'bmutVec<u8>) -> &'b[u8]{&buf[..]}}/// Borrowed reader, zero-copyimpl<'i>BufferedInput<'i,()>for&'i[u8]{/// Directly borrow data from `self`, do not copy,/// return data that borrow from `self`fnread(&mutself,_buf:()) -> &'i[u8]{self}}#[cfg(test)]mod test {/// Helper trait for `generic_tests` cratetraitStorage<'b>:Default{typeBuffer;/// Returns buffer for `BufferedInput::read`fnbuffer(&'bmutself) -> Self::Buffer;}impl<'b>Storage<'b>for(){typeBuffer = ();fnbuffer(&'bmutself){}}impl<'b>Storage<'b>forVec<u8>{typeBuffer = &'bmutVec<u8>;fnbuffer(&'bmutself) -> Self::Buffer{self}}fntest<S>()wherefor<'b>S:Storage<'b>,for<'b>&'b[u8]:crate::BufferedInput<'b, <SasStorage<'b>>::Buffer>,{letmut storage = S::default();
storage.buffer();}mod submod {usesuper::Storage;usecrate::BufferedInput;externcrate test;#[cfg(test)]#[rustc_test_marker]pubconst test: test::TestDescAndFn = test::TestDescAndFn{desc: test::TestDesc{name: test::StaticTestName("test::submod::test"),ignore:false,allow_fail:false,compile_fail:false,no_run:false,should_panic: test::ShouldPanic::No,test_type: test::TestType::UnitTest,},testfn: test::StaticTestFn(|| test::assert_test_result(test())),};fntest<S>()wherefor<'b>S:Storage<'b>,for<'b>&'b[u8]:BufferedInput<'b, <SasStorage<'b>>::Buffer>,{letmut storage = S::default();
storage.buffer();}}/// Tests for reader that generates events that borrow from the provided buffermod buffered {#[allow(unused_imports)]usesuper::*;externcrate test;#[cfg(test)]#[rustc_test_marker]pubconst test: test::TestDescAndFn = test::TestDescAndFn{desc: test::TestDesc{name: test::StaticTestName("test::buffered::test"),ignore:false,allow_fail:false,compile_fail:false,no_run:false,should_panic: test::ShouldPanic::No,test_type: test::TestType::UnitTest,},testfn: test::StaticTestFn(|| test::assert_test_result(test())),};fntest(){mod shim {pub(super)mod _generic_tests_call_sig {#[allow(unused_imports)]usesuper::super::super::*;pub(insuper::super)structArgs{}pub(super)typeRet = ();}#[allow(unused_imports)]usesuper::super::*;pub(super)unsafefnshim(_args: _generic_tests_call_sig::Args,) -> _generic_tests_call_sig::Ret{super::super::test::<Vec<u8>>()}}let args = shim::_generic_tests_call_sig::Args{};unsafe{ shim::shim(args)}}}/// Tests for reader that generates events that borrow from the inputmod borrowed {#[allow(unused_imports)]usesuper::*;externcrate test;#[cfg(test)]#[rustc_test_marker]pubconst test: test::TestDescAndFn = test::TestDescAndFn{desc: test::TestDesc{name: test::StaticTestName("test::borrowed::test"),ignore:false,allow_fail:false,compile_fail:false,no_run:false,should_panic: test::ShouldPanic::No,test_type: test::TestType::UnitTest,},testfn: test::StaticTestFn(|| test::assert_test_result(test())),};fntest(){mod shim {pub(super)mod _generic_tests_call_sig {#[allow(unused_imports)]usesuper::super::super::*;pub(insuper::super)structArgs{}pub(super)typeRet = ();}#[allow(unused_imports)]usesuper::super::*;pub(super)unsafefnshim(_args: _generic_tests_call_sig::Args,) -> _generic_tests_call_sig::Ret{super::super::test::<()>()}}let args = shim::_generic_tests_call_sig::Args{};unsafe{ shim::shim(args)}}}}#[rustc_main]pubfnmain() -> (){externcrate test;
test::test_main_static(&[&test,&test,&test])}
The text was updated successfully, but these errors were encountered:
Thank you for the feature suggestion. The macro does not look into submodules as currently implemented.
It should be possible to transform [test] functions defined in submodules, by instantiating into the replicated submodule tree under the instantiation module, and emit a glob import from the original module of a test into its instantiation submodules in order for all the support code and imported names from the original module to be visible to the instantiation. But it's a substantial amount of work I'm not ready to commit to at the moment.
I trying to replace macro_rules-based tests in my PR with generic-tests one. Everyseen works fine when I define test function in the
test
module (which is annotated with#[generic_tests::define]
), but when I move my test into innertest::submod
module, the compilation fails with impossible to find a trait.I want to define my tests tree, including tests in the inner modules, like I do that for the ordinary tests framework, and then copy that tree for every set of template parameters. Is this possible?
The code that demonstrates problem:
`cargo expand --tests` output
The text was updated successfully, but these errors were encountered: