docopt / docopt.rs

Docopt for Rust (command line argument parser).
The Unlicense
750 stars 83 forks source link

Compiling tests fails #11

Closed eliovir closed 10 years ago

eliovir commented 10 years ago

After cloning the repository, I tried to run cargo test, but it fails with

docopt.rs/examples/macro.rs:4:18: 4:45 error: can't find crate for `docopt_macros`
docopt.rs/examples/macro.rs:4 #[phase(plugin)] extern crate docopt_macros;
                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
docopt.rs/examples/cp.rs:3:18: 3:45 error: can't find crate for `docopt_macros`
docopt.rs/examples/cp.rs:3 #[phase(plugin)] extern crate docopt_macros;
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
docopt.rs/examples/rustc.rs:3:18: 3:45 error: can't find crate for `docopt_macros`
docopt.rs/examples/rustc.rs:3 #[phase(plugin)] extern crate docopt_macros;
                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
docopt.rs/examples/add.rs:4:18: 4:45 error: can't find crate for `docopt_macros`
docopt.rs/examples/add.rs:4 #[phase(plugin)] extern crate docopt_macros;
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~

The same problem occurs while running directly rustc: rustc -L ./build examples/add.rs

examples/add.rs:4:18: 4:45 error: can't find crate for `docopt_macros`
examples/add.rs:4 #[phase(plugin)] extern crate docopt_macros;
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
BurntSushi commented 10 years ago

Oh, neat. I didn't realize Cargo automatically checked examples for me. (I've still been using make test.)

I don't really know how to use cargo test. Specifically, the examples require that docopt_macros is built. So there needs to be a way to specify a dependency on docopt_macros in root/Cargo.toml for testing?

@alexcrichton Any ideas? Is this possible yet?

alexcrichton commented 10 years ago

This is little unfortunate, there's not necessarily a great way to express this as you'll end up with in theory some circular dependencies.

That being said, if you add this to your top-level Cargo.toml the examples will build:

[dev-dependencies.docopt_macros]
path = "docopt_macros"

This in theory induces a circular dependency of docopt with itself, but it turns out that your Cargo.toml for docopt_macros depends on the git version of docopt, not the local version. This means that when you run cargo test you'll build two versions of the docopt library, then the tests will pass.

Another alternative would be to have /examples and /docopt_macros/examples. If you split it like that then everything will "just work" because the examples that use the docopt_macros crate will have it available and the other examples won't. Does that make sense?

BurntSushi commented 10 years ago

Ah ha! Splitting the examples makes a lot of sense. I'll probably go that route. Seems simplest.

So when I do that, a new problem arises. When I cd into docopt_macros and run cargo test, it tries to compile docopt_macros with the git version of docopt. But really, I'd like to test it against my local copy before pushing to the world. I could modify my config to use path, but is there any other way? (I tried adding dev-dependencies.docopt to docopt_macro's Cargo.toml, but it ends up compiling both versions of docopt when running cargo test (understanable) and that leads to trouble.)

BurntSushi commented 10 years ago

Hmm, I can't seem to get any kind of cargo test to work in ./docopt_macros. I've tried using path instead of git to point to the docopt dependency, but cargo tells me:

[andrew@Liger docopt_macros] cargo test
   Compiling docopt v0.6.0 (file:/home/andrew/data/projects/docopt.rs/docopt_macros)
   Compiling docopt_macros v0.6.0 (file:/home/andrew/data/projects/docopt.rs/docopt_macros)
/home/andrew/data/projects/docopt.rs/docopt_macros/target/test/docopt_macros-754b83a3bcc7f2df: error while loading shared libraries: libdocopt-bea495e631e19a4e.so: cannot open shared object file: No such file or directory
Could not execute process `/home/andrew/data/projects/docopt.rs/docopt_macros/target/test/docopt_macros-754b83a3bcc7f2df` (status=127)

Cargo.toml:

[package]
name = "docopt_macros"
version = "0.6.0"
authors = ["Andrew Gallant <jamslam@gmail.com>"]

[[lib]]
name = "docopt_macros"
path = "src/macro.rs"
plugin = true

[dependencies.docopt]
# git = "https://github.com/BurntSushi/docopt.rs" 
path = "/home/andrew/data/projects/docopt.rs"
alexcrichton commented 10 years ago

Hm, I think that's a bug in rustdoc, I'll look into it!

alexcrichton commented 10 years ago

cargo*

alexcrichton commented 10 years ago

Should be fixed in master now!

BurntSushi commented 10 years ago

Great, that seems to fix the docopt_macros problem. Thanks! Although, now in docopt, cargo test runs rustdoc, but that fails because the doc tests require docopt_macros. I'll try to file a proper bug report.