[rust-dev] crate_type = "lib" and testing

Niko Matsakis niko at alum.mit.edu
Tue Apr 10 20:28:36 PDT 2012


the reason is that there is no need for the `mod test` directive in 
test.rc.  This effectively creates loads the `test.rs` file twice, once 
in the root namespace and once as the module `test`.


Niko

On 4/10/12 8:07 PM, Alexander Stavonin wrote:
> Hi all,
>
> I've faced with strange behavior of #[test] command. Could someone 
> explain me is it bug or feature.
>
> --------- test.rc ----------
> #[link (name="test",
>         vers = "0.1",
>         uuid = "B019C86D-C7ED-4263-810E-B12A33E6954C")];
> #[crate_type = "lib"];
>
> use std;
> mod test;
> ------ END -------
>
>
> --------- test.rs ----------
> fn foo() -> bool { ret true }
>
> #[test]
> fn foo_test() {
>     assert foo() == true;
> }
> ------ END -------
>
> Compiling and run it:
>
> astavonin:/Users/../RustTests: rustc --test test.rc
> warning: no debug symbols in executable (-arch x86_64)
> astavonin:/Users/../RustTests: ./test
>
> running *_2_* tests
> test foo_test ... ok
> test test::foo_test ... ok
>
> result: ok. 2 passed; 0 failed; 0 ignored
>
> Question: Why 2 tests was created from just 1 foo_test() test 
> function? Also, it's looks like both tests are running parallel and 
> sometimes it provoke segmentation faults in case of more complex tests.
>
> Regards,
> Alexander.
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev



More information about the Rust-dev mailing list