1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! test-cdylib is a library for dynamically linking to cdylib projects from
//! test code. This allows testing for the existence of exported items.
//!
//! # Testing a cdylib project
//!
//! A cdylib project can be tested like this:
//!
//! ```no_run
//! #[test]
//! fn api_test() {
//! let dylib_path = test_cdylib::build_current_project();
//!
//! // Or load the shared library using any other method of your choice.
//! let dylib = dlopen::symbor::Library::open(&dylib_path).unwrap();
//!
//! // Test the api as necessary.
//! }
//! ```
//!
//! This will build the current project, if it is not already built, and return
//! the path to the compiled library.
//!
//! ## Testing a cdylib building library
//!
//! Libraries that are meant to help create cdylib interfaces can be tested in two
//! ways. First is to link to an example, e.g.
//!
//! ```rust
//! #[test]
//! fn api_gen_test() {
//! let dylib_path = test_cdylib::build_example("example");
//!
//! // Or load the shared library using any other method of your choice.
//! let dylib = dlopen::symbor::Library::open(&dylib_path).unwrap();
//!
//! // Test the api as necessary.
//! }
//! ```
//!
//! This will build the example and return the path to the compiled library.
//!
//! The second way is to build a file as a cdylib, e.g.
//!
//! ```rust
//! #[test]
//! fn api_gen_test() {
//! let dylib_path = test_cdylib::build_path("tests/cdylib/api_test.rs");
//!
//! // Or load the shared library using any other method of your choice.
//! let dylib = dlopen::symbor::Library::open(&dylib_path).unwrap();
//!
//! // Test the api as necessary.
//! }
//! ```
//!
//! This will build the given file as a cdylib project, and return the path to
//! the compiled library. All dependencies and dev-dependencies are available. Note
//! that this will cause all dependencies to be rebuilt, which can slow down testing
//! significantly.
//!
//! ## Multiple tests with the same library
//!
//! Multiple tests can link to the same library by using
//! [once_cell](https://crates.io/crates/once_cell) to contain the path to the
//! library, e.g.
//!
//! ```rust
//! use std::path::PathBuf;
//! use once_cell::sync::Lazy;
//! static LIB_PATH: Lazy<PathBuf> = Lazy::new(|| test_cdylib::build_current_project());
//! ```
//!
//! The same can be done for both `build_example` and `build_path`.
use ;
/// Builds the given file as a cdylib and returns the path to the compiled object.
/// Builds the current project as a cdylib and returns the path to the compiled object.
/// Builds the given example as a cdylib and returns the path to the compiled object.