Skip to content

Commit 61a51d6

Browse files
committed
spirv-builder: clap testing
1 parent 9b3afbe commit 61a51d6

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
run: cargo test -p rustc_codegen_spirv --release --no-default-features --features "use-installed-tools"
5151

5252
- name: workspace test (excluding examples & difftest)
53-
run: cargo test --release --workspace --exclude "example-runner-*" --exclude "difftest*" --no-default-features --features use-installed-tools,include_str
53+
run: cargo test --release --workspace --exclude "example-runner-*" --exclude "difftest*" --no-default-features --features use-installed-tools,include_str,clap
5454

5555
# Examples
5656
- name: cargo check examples

crates/spirv-builder/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
#![doc = include_str!("../README.md")]
7474

7575
mod depfile;
76+
#[cfg(test)]
77+
mod tests;
7678
#[cfg(feature = "watch")]
7779
mod watch;
7880

crates/spirv-builder/src/tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#[cfg(feature = "clap")]
2+
mod clap {
3+
pub use crate::*;
4+
use clap::Parser;
5+
6+
/// look at the output of this test to see what `--help` prints
7+
#[test]
8+
fn test_clap_help() {
9+
match SpirvBuilder::try_parse_from(["", "--help"]) {
10+
Ok(_) => panic!("help must fail to parse"),
11+
Err(e) => {
12+
let e = e.to_string();
13+
println!("{}", e);
14+
assert!(e.contains("--target"));
15+
}
16+
};
17+
}
18+
19+
#[test]
20+
fn test_clap_target() {
21+
let env = SpirvTargetEnv::OpenGL_4_2;
22+
let builder = SpirvBuilder::try_parse_from(["", "--target", &env.target_triple()])
23+
.map_err(|e| e.to_string())
24+
.unwrap();
25+
assert_eq!(builder.target, Some(env));
26+
}
27+
}

0 commit comments

Comments
 (0)