Skip to content

Commit

Permalink
more output_path() test in capnpc-test, and make it actually test som…
Browse files Browse the repository at this point in the history
…ething interesting
  • Loading branch information
dwrensha committed Jun 5, 2023
1 parent caedfcb commit 977b3db
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
12 changes: 1 addition & 11 deletions capnpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,7 @@ impl CompilerCommand {
#[test]
#[cfg_attr(miri, ignore)]
fn compiler_command_new_no_out_dir() {
std::env::remove_var("OUT_DIR");
let error = CompilerCommand::new().run().unwrap_err().description;
assert!(error.starts_with("Could not access `OUT_DIR` environment variable"));
}

#[test]
#[cfg_attr(miri, ignore)]
fn compiler_command_with_output_path_no_out_dir() {
let error = CompilerCommand::new()
.output_path("foo")
.run()
.unwrap_err()
.description;
assert!(error.starts_with("Error while trying to execute `capnp compile`"));
}
11 changes: 11 additions & 0 deletions capnpc/test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ fn main() {
])
.run()
.expect("compiling schema");

let mut output_path =
std::path::PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR env var is not set"));

// `capnp compile` will create this directory
output_path.push("inner-output-path");
capnpc::CompilerCommand::new()
.file("test-output-path.capnp")
.output_path(output_path)
.run()
.expect("compiling schema")
}
9 changes: 9 additions & 0 deletions capnpc/test/test-output-path.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Schema to use to test `CompilerCommand::output_path()`.

@0xbc9d501a1b13e0e9;

struct Foo {}

struct Bar {
foo @0 : Foo;
}
7 changes: 7 additions & 0 deletions capnpc/test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ pub mod test_in_src_prefix_dir_capnp {
include!(concat!(env!("OUT_DIR"), "/test_in_src_prefix_dir_capnp.rs"));
}

pub mod test_output_path_capnp {
include!(concat!(
env!("OUT_DIR"),
"/inner-output-path/test_output_path_capnp.rs"
));
}

#[cfg(test)]
mod test_util;

Expand Down

0 comments on commit 977b3db

Please sign in to comment.