Skip to content

Commit 5e8ce09

Browse files
authored
cppwinrt should consistently panic on failure (#3415)
1 parent d02c977 commit 5e8ce09

File tree

7 files changed

+17
-22
lines changed

7 files changed

+17
-22
lines changed

crates/libs/cppwinrt/readme.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ version = "0.1"
1616
Use `cppwinrt` function as needed:
1717

1818
```rust
19-
match cppwinrt::cppwinrt(["-help"]) {
20-
Ok(output) => println!("{output}"),
21-
Err(error) => println!("{error}"),
22-
};
19+
println!("{}", cppwinrt::cppwinrt(["-help"]));
2320
```
2421

2522
Source:

crates/libs/cppwinrt/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const VERSION: &str = "2.0.240405.15";
66
/// Calls the C++/WinRT compiler with the given arguments.
77
///
88
/// Use `cppwinrt["-help"]` for available options.
9-
pub fn cppwinrt<I, S>(args: I) -> Result<String, String>
9+
pub fn cppwinrt<I, S>(args: I) -> String
1010
where
1111
I: IntoIterator<Item = S>,
1212
S: AsRef<std::ffi::OsStr>,
@@ -27,9 +27,9 @@ where
2727
_ = std::fs::remove_file(path);
2828

2929
if output.status.success() {
30-
Ok(String::from_utf8_lossy(&output.stdout).to_string())
30+
String::from_utf8_lossy(&output.stdout).to_string()
3131
} else {
32-
Err(String::from_utf8_lossy(&output.stderr).to_string())
32+
panic!("{}", String::from_utf8_lossy(&output.stderr))
3333
}
3434
}
3535

@@ -38,11 +38,14 @@ mod tests {
3838
use crate::*;
3939

4040
#[test]
41-
fn test() {
42-
let ok = cppwinrt(["-help"]).unwrap();
43-
assert!(ok.contains(VERSION), "unexpected version");
41+
#[should_panic(expected = "'-invalid' is not supported")]
42+
fn invalid_arg() {
43+
cppwinrt(["-invalid"]);
44+
}
4445

45-
let err = cppwinrt(["-invalid"]).unwrap_err();
46-
assert!(err.contains("'-invalid' is not supported"));
46+
#[test]
47+
fn unexpected_version() {
48+
let ok = cppwinrt(["-help"]);
49+
assert!(ok.contains(VERSION), "unexpected version");
4750
}
4851
}

crates/samples/components/json_validator_winrt_client_cpp/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ fn main() {
1414
&format!("{}\\System32\\WinMetadata", env!("windir")),
1515
"-out",
1616
&include,
17-
])
18-
.unwrap();
17+
]);
1918

2019
cc::Build::new()
2120
.cpp(true)

crates/tests/winrt/composable_client/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ fn main() {
2626
"../../../libs/bindgen/default",
2727
"-out",
2828
&include,
29-
])
30-
.unwrap();
29+
]);
3130

3231
cc::Build::new()
3332
.cpp(true)

crates/tests/winrt/constructors_client/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ fn main() {
2626
"../../../libs/bindgen/default",
2727
"-out",
2828
&include,
29-
])
30-
.unwrap();
29+
]);
3130

3231
cc::Build::new()
3332
.cpp(true)

crates/tests/winrt/noexcept/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ fn main() {
4747
&format!("{}\\System32\\WinMetadata", env!("windir")),
4848
"-out",
4949
&include,
50-
])
51-
.unwrap();
50+
]);
5251

5352
cc::Build::new()
5453
.cpp(true)

crates/tests/winrt/ref_params/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ fn main() {
4747
&format!("{}\\System32\\WinMetadata", env!("windir")),
4848
"-out",
4949
&include,
50-
])
51-
.unwrap();
50+
]);
5251

5352
cc::Build::new()
5453
.cpp(true)

0 commit comments

Comments
 (0)