Skip to content
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

Add test case for OUT_DIR in tests. #954

Merged
merged 8 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/out_dir_in_tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load(
"//rust:rust.bzl",
"rust_library",
"rust_test",
)
load("//cargo:cargo_build_script.bzl", "cargo_build_script")

cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
)

rust_library(
name = "demo_lib",
srcs = [
"src/lib.rs",
],
deps = [":build_script"],
)

rust_test(
name = "demo_lib_test",
crate = ":demo_lib",
)

# Add a test suite once the unit test works.
8 changes: 8 additions & 0 deletions test/out_dir_in_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "out_dir_integration_tests"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
11 changes: 11 additions & 0 deletions test/out_dir_in_tests/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;

fn main() -> std::io::Result<()> {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut file = File::create(out_path.join("test_content.txt"))?;
file.write_all(b"Test content")?;
Ok(())
}
16 changes: 16 additions & 0 deletions test/out_dir_in_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[cfg(test)]
mod tests {
use std::env;
use std::fs;
use std::path::PathBuf;

#[test]
fn can_find_the_out_dir_file() {
for (key, value) in env::vars() {
println!("{}: {}", key, value);
}
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
sayrer marked this conversation as resolved.
Show resolved Hide resolved
let contents = fs::read_to_string(out_path.join("test_content.txt")).unwrap();
assert_eq!("FAIL ON PURPOSE", contents);
}
}
10 changes: 10 additions & 0 deletions test/out_dir_in_tests/tests/out_dir_reader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::env;
use std::fs;
use std::path::PathBuf;

#[test]
fn can_find_the_out_dir_file() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
sayrer marked this conversation as resolved.
Show resolved Hide resolved
let contents = fs::read_to_string(out_path.join("test_content.txt")).unwrap();
assert_eq!("Test content", contents);
}