Skip to content

Commit e9b91b4

Browse files
authored
Use conventional testing for windows_slim_errors (#3132)
1 parent dffa8b0 commit e9b91b4

File tree

11 files changed

+71
-46
lines changed

11 files changed

+71
-46
lines changed

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
rustflags = [
33
# "--cfg", "windows_debugger_visualizer",
44
# "--cfg", "windows_raw_dylib",
5+
# "--cfg", "windows_slim_errors",
56
# "-C", "target-feature=+crt-static",
67
]

.github/workflows/msrv-windows-result.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,3 @@ jobs:
2929
run: cargo check -p windows-result --all-features
3030
- name: Check Default Features
3131
run: cargo check -p windows-result
32-
- name: Check Slim Errors
33-
shell: pwsh
34-
run: |
35-
$ErrorActionPreference = 'Stop'
36-
$env:RUSTFLAGS = '--cfg=windows_slim_errors'
37-
38-
# This will show the size of Error, which lets us confirm that RUSTFLAGS was set.
39-
cargo test -p windows-result --lib -- --nocapture --test-threads=1
40-
41-
cargo check -p windows-result

.github/workflows/slim_errors.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: slim_errors
2+
3+
on:
4+
pull_request:
5+
push:
6+
paths-ignore:
7+
- '.github/ISSUE_TEMPLATE/**'
8+
branches:
9+
- master
10+
11+
env:
12+
RUSTFLAGS: -Dwarnings --cfg windows_slim_errors
13+
14+
jobs:
15+
check:
16+
strategy:
17+
matrix:
18+
include:
19+
- target: x86_64-pc-windows-msvc
20+
- target: i686-pc-windows-msvc
21+
- target: x86_64-pc-windows-gnu
22+
- target: i686-pc-windows-gnu
23+
runs-on:
24+
- windows-latest
25+
runs-on: ${{ matrix.runs-on }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
30+
- name: Update toolchain
31+
run: rustup update --no-self-update nightly && rustup default nightly-${{ matrix.target }}
32+
33+
- name: Add toolchain target
34+
run: rustup target add ${{ matrix.target }}
35+
36+
- name: Fix environment
37+
uses: ./.github/actions/fix-environment
38+
39+
- name: Test
40+
run: cargo test -p test_result

crates/libs/result/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ workspace = true
2121
default-target = "x86_64-pc-windows-msvc"
2222
targets = []
2323

24-
[dependencies]
25-
static_assertions = "1.0"
26-
2724
[dependencies.windows-targets]
2825
version = "0.52.5"
2926
path = "../targets"

crates/libs/result/src/error.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ impl Ord for Error {
257257
}
258258
}
259259

260-
static_assertions::assert_impl_all!(Error: Send, Sync);
261-
262260
use error_info::*;
263261

264262
#[cfg(all(windows, not(windows_slim_errors)))]
@@ -395,11 +393,4 @@ mod error_info {
395393
core::ptr::null_mut()
396394
}
397395
}
398-
399-
// If we are using "slim" Error objects, then we can rely on Result<()>
400-
// having a representation that is equivalent to HRESULT.
401-
static_assertions::const_assert_eq!(
402-
size_of::<core::result::Result<(), Error>>(),
403-
size_of::<HRESULT>()
404-
);
405396
}

crates/libs/result/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,3 @@ pub use hresult::HRESULT;
3636

3737
/// A specialized [`Result`] type that provides Windows error information.
3838
pub type Result<T> = core::result::Result<T, Error>;
39-
40-
#[cfg(test)]
41-
mod tests;

crates/libs/result/src/tests.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

crates/tests/result/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ path = "../../libs/targets"
1616

1717
[dependencies]
1818
helpers = { package = "test_helpers", path = "../helpers" }
19+
static_assertions = "1.0"
20+
21+
[lints.rust]
22+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(windows_slim_errors)'] }

crates/tests/result/tests/error.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ fn new() {
2424

2525
let e = Error::new(E_INVALIDARG, "test message");
2626
assert_eq!(e.code(), E_INVALIDARG);
27-
assert!(!e.as_ptr().is_null());
28-
assert_eq!(e.message(), "test message");
27+
28+
if cfg!(windows_slim_errors) {
29+
assert!(e.as_ptr().is_null());
30+
assert_eq!(e.message(), "The parameter is incorrect.");
31+
} else {
32+
assert!(!e.as_ptr().is_null());
33+
assert_eq!(e.message(), "test message");
34+
}
2935
}
3036

3137
#[test]

crates/tests/result/tests/hresult.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ fn from_result() {
8080
let result: Result<()> = Err(Error::new(E_INVALIDARG, "test message"));
8181
let err = HRESULT::from(result).ok().unwrap_err();
8282
assert_eq!(err.code(), E_INVALIDARG);
83-
assert_eq!(err.message(), "test message");
83+
84+
if cfg!(windows_slim_errors) {
85+
assert_eq!(err.message(), "The parameter is incorrect.");
86+
} else {
87+
assert_eq!(err.message(), "test message");
88+
}
8489
}
8590

8691
#[test]

0 commit comments

Comments
 (0)