Skip to content

Commit b790781

Browse files
committed
test for reset cache problem
1 parent c91fe8c commit b790781

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

.github/workflows/main.yml

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ jobs:
1212
- uses: actions/checkout@master
1313
- name: Install Rust
1414
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
15+
- name: Check versions
16+
run: |
17+
set -e
18+
cargo --version
19+
rustc --version
20+
cmake --version
21+
gcc --version
22+
clang --version
23+
echo "end of versions checking"
24+
shell: bash
1525
- run: cargo test
1626

1727
rustfmt:

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ categories = ["development-tools::build-utils"]
1515

1616
[dependencies]
1717
cc = "1.0.41"
18+
19+
[dev-dependencies]
20+
tempfile = "3.1.0"
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
extern crate tempfile;
2+
3+
use std::{env, error::Error, fs, path::Path};
4+
5+
#[test]
6+
fn handling_reset_cache_after_set_var() {
7+
let tmp_dir = tempfile::tempdir().unwrap();
8+
9+
fill_dir(tmp_dir.path()).unwrap();
10+
11+
if cfg!(all(
12+
target_os = "linux",
13+
target_arch = "x86_64",
14+
target_vendor = "unknown"
15+
)) {
16+
env::set_var("TARGET", "x86_64-unknown-linux-gnu");
17+
env::set_var("HOST", "x86_64-unknown-linux-gnu");
18+
env::set_var("OUT_DIR", tmp_dir.path());
19+
env::set_var("PROFILE", "debug");
20+
env::set_var("OPT_LEVEL", "0");
21+
env::set_var("DEBUG", "true");
22+
let dst = cmake::Config::new(tmp_dir.path())
23+
.define("OPT1", "False")
24+
.build_target("all")
25+
.build()
26+
.join("build");
27+
28+
assert!(fs::read_to_string(dst.join("CMakeCache.txt"))
29+
.unwrap()
30+
.contains("OPT1:BOOL=False"));
31+
env::set_var("CC", "clang");
32+
env::set_var("CXX", "clang++");
33+
let dst = cmake::Config::new(tmp_dir.path())
34+
.define("OPT1", "False")
35+
.build_target("all")
36+
.build()
37+
.join("build");
38+
39+
assert!(fs::read_to_string(dst.join("CMakeCache.txt"))
40+
.unwrap()
41+
.contains("OPT1:BOOL=False"));
42+
}
43+
}
44+
45+
fn fill_dir(tmp_dir: &Path) -> Result<(), Box<dyn Error>> {
46+
fs::write(
47+
tmp_dir.join("CMakeLists.txt"),
48+
r#"
49+
project(xyz)
50+
cmake_minimum_required(VERSION 3.9)
51+
52+
option(OPT1 "some option" ON)
53+
add_executable(xyz main.cpp)
54+
"#,
55+
)?;
56+
fs::write(
57+
tmp_dir.join("main.cpp"),
58+
r#"
59+
#include <cstdio>
60+
#define DO_STRINGIFY(x) #x
61+
#define STRINGIFY(x) DO_STRINGIFY(x)
62+
int main() {
63+
printf("option: %s\n", STRINGIFY(OPT1));
64+
}
65+
"#,
66+
)?;
67+
Ok(())
68+
}

0 commit comments

Comments
 (0)