Skip to content

Allow tests to read data dynamically from a package #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huonw opened this issue Aug 25, 2014 · 4 comments · Fixed by #434
Closed

Allow tests to read data dynamically from a package #433

huonw opened this issue Aug 25, 2014 · 4 comments · Fixed by #434

Comments

@huonw
Copy link
Member

huonw commented Aug 25, 2014

E.g. https://github.com/kmcallister/html5ever has tests that dynamically, at test time, (#431) construct tests from the test-case descriptions in https://github.com/html5lib/html5lib-tests submodule. At the moment it is using Makefiles to build, and just passes around an environment variable to point to the right place (i.e. the root directory) allowing the test runner to reach into the html5lib-tests folder at runtime.

Cargo doesn't provide an easy way to do this, other than relying on the position of the test runner binary itself. It would be nice to either enforce this position so we can rely on it, or, better, pass an environment variable pointing at the right place (while both building and running tests, maybe).

(Or something else that achieves the same goal.)

@SimonSapin
Copy link
Contributor

I’d like to generalize this request to all programs, not just tests. Program may want to ship resources (images, stylesheets, documents, …) other than code, for use at runtime. Currently, include_str!() and include_bin!() can be used for this, but they bloat the program’s binaries and require re-building the program when any resource changes.

Rust and Cargo should have a set of conventions (and possibly some library support) for having arbitrary files somewhere the program can use them with std::io::File::open. For programs "installed" on Linux, this probably should be in /usr/share/.

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Aug 25, 2014
All subprocesses will now be invoked with CARGO_MANIFEST_DIR pointing at the
root of the source directory that they are working on (compiling). This commit
also reorganizes the version environment variables to use the new
infrastructure.

Closes rust-lang#433
@alexcrichton
Copy link
Member

In terms of installation, that's going to have to be a bridge that we cross at a later date. In terms of extending this to non-tests, would the environment variable solution work ok?

@SimonSapin
Copy link
Contributor

So cargo run would take care of setting that variable? Yeah, that would work.

@alexcrichton
Copy link
Member

Yeah basically all cargo subprocesses (compilation, tests, running, etc) would have the environment variable.

bors added a commit that referenced this issue Aug 25, 2014
All subprocesses will now be invoked with CARGO_MANIFEST_DIR pointing at the root of the
source directory that they are working on (compiling). This commit also
reorganizes the version environment variables to use the new infrastructure.

Closes #433
@bors bors closed this as completed in #434 Aug 25, 2014
alexcrichton added a commit to alexcrichton/cargo that referenced this issue Sep 2, 2014
All subprocesses will now be invoked with CARGO_MANIFEST_DIR pointing at the
root of the source directory that they are working on (compiling). This commit
also reorganizes the version environment variables to use the new
infrastructure.

Closes rust-lang#433
bors added a commit to alexcrichton/cargo that referenced this issue Sep 2, 2014
All subprocesses will now be invoked with CARGO_MANIFEST_DIR pointing at the root of the
source directory that they are working on (compiling). This commit also
reorganizes the version environment variables to use the new infrastructure.

Closes rust-lang#433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants