Skip to content

Latest commit

 

History

History
86 lines (66 loc) · 2.43 KB

files.md

File metadata and controls

86 lines (66 loc) · 2.43 KB

Sending project files to the devices

Some tests are relying on the presence of files at relative paths to be able to proceed. But we can not always control where we will be executing from (we can not always do cd someplace before running the tests).

So, the tests are "bundled" in the following way:

  • root dinghy test directory
    • test_executable
    • recursive copy of the not-ignorable files and directories from your projects
    • test_data contains configurable data to be sent to the device
      • some_file
      • some_dir

Anything in .gitignore or .dinghyignore will not be bundled.

To open your test file easily, you can use the dinghy-test crate in your tests which contains a helper function to access your project directory:

#[cfg(test)]
extern crate dinghy_test;


#[cfg(test)]
mod tests {
    #[test]
    fn my_test() {
        let my_file_path = dinghy_test::test_project_path().join("tests/data_1.txt");
        // ...
    }
}

Sending more files to the devices

Now let's assume you have out-of-repository files to send over. You can do that by adding it in .dinghy.toml (you'll probably want this one in the project directory, or just above it if the data is shared among several cargo projects).

[test_data]
the_data = "../data-2017-02-05"
conf_file = "/etc/some/file"

The keys are the name under which to look for files below "test_data" in the bundles, and the values are what to be copied (from your development workstation).

By default anything in .gitignore or .dinghyignore is not copied, however if you need .gitignore'd files to be copied it can be excluded by adding copy_git_ignored = true:

[test_data]
the_data = { source = "../data-2017-02-05", copy_git_ignored = true }
conf_file = "/etc/some/file"

Then you can use again the dinghy-test crate to access your specific test data directory:

#[cfg(test)]
extern crate dinghy_test;

#[cfg(test)]
mod tests {
    #[test]
    fn my_test() {
        let my_test_data_path = dinghy_test::test_file_path("the_data");
        let my_test_file_path = dinghy_test::test_file_path("conf_file");
        // ...
    }
}

In order to accomodate tests running in "cargo native" and "dinghy mode" you may define and use a helper like that in your tests to find the test files:

#[cfg(test)]
fn test_resources() -> std::path::PathBuf {
    dinghy_test::try_test_file_path("test-resources").unwrap_or("../test-resources".into())
}