[rust-dev] Using 'mod' for test code

Allen Welkie allen.welkie at gmail.com
Wed Jul 23 10:32:17 PDT 2014

I'm having an issue with creating a separate testing file for a program I'm
writing. I have a file called 'myprogram.rs', which imports complex numbers
with the following

  extern crate num;
  use num::complex::Complex;

and then defines a bunch of functions. I want to test these functions in a
separate file. So I created 'testprogram.rs' and import the myprogram
functions using the 'mod' keyword:

  mod myprogram;

But when I try to compile test.rs with the --test flag, I get the following
error for myprogram.rs:

  "unresolved import 'num::complex::Complex'. Did you mean

What's going on here? How can I import my program to create a test suite.
Also, is this the preferred way of creating a test suite (using the 'mod'
keyword)? Or should I compile 'myprogram.rs' into a crate and import the
crate into 'test.rs'?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140723/4b15ea26/attachment.html>

More information about the Rust-dev mailing list