Skip to content

Commit a13252d

Browse files
committed
CI add a native test for WinDebugSink on Windows
1 parent 674bf72 commit a13252d

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,46 @@ jobs:
255255
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[1].MESSAGE == "[demo] [error] error message from spdlog-rs\'s JournaldSink { error_code=114514 }\n"'
256256
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[1].PRIORITY == "3" and .[1].CODE_FILE == "linux.rs" and .[1].CODE_LINE == "16" and .[1].TID != null'
257257
258+
test-native-windows:
259+
strategy:
260+
fail-fast: false
261+
runs-on: 'windows-latest'
262+
steps:
263+
- name: Checkout repository
264+
uses: actions/checkout@v4
265+
- name: Disable bench dependencies
266+
run: ./.github/workflows/disable-bench-deps.sh
267+
- name: Install DebugView
268+
run: choco install dbgview
269+
- name: Restore cargo caches
270+
uses: Swatinem/rust-cache@v2
271+
- name: Build example
272+
run: |
273+
cargo build --example native_windows --features native,source-location --verbose
274+
mv ./target/debug/examples/native_windows ./target/debug/examples/native_windows_srcloc
275+
cargo build --example native_windows --features native --verbose
276+
- name: Run and test
277+
run: |
278+
set -x
279+
280+
# Microsoft styled CLI options start with `/` and need to be doubled to escape in bash.
281+
dbgview //l ./dbgview.log
282+
# Wait for dbgview to start up and create the log file
283+
while [ ! -f ./dbgview.log ]; do sleep 1; done
284+
285+
./target/debug/examples/native_windows
286+
./target/debug/examples/native_windows_srcloc
287+
288+
# Wait for dbgview to flush the log file
289+
while [ ! -s ./dbgview.log ]; do sleep 1; done
290+
dbgview //q
291+
292+
cat ./dbgview.log
293+
cat ./dbgview.log | grep "\[demo] \[info] info message from spdlog-rs's WinDebugSink"
294+
cat ./dbgview.log | grep "\[demo] \[error] error message from spdlog-rs's WinDebugSink { error_code=114514 }"
295+
cat ./dbgview.log | grep -E "\[demo] \[info] \[native_windows, .+.rs:[0-9]+] info message from spdlog-rs's WinDebugSink"
296+
cat ./dbgview.log | grep -E "\[demo] \[error] \[native_windows, .+.rs:[0-9]+] error message from spdlog-rs's WinDebugSink { error_code=114514 }"
297+
258298
test-native-android:
259299
strategy:
260300
fail-fast: false

spdlog/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ name = "native_linux"
197197
path = "examples/native/linux.rs"
198198
required-features = ["native", "libsystemd"]
199199
[[example]]
200+
name = "native_windows"
201+
path = "examples/native/windows.rs"
202+
required-features = ["native"]
203+
[[example]]
200204
name = "native_android"
201205
path = "examples/native/android.rs"
202206
required-features = ["native", "android-ndk"]

spdlog/examples/native/windows.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[cfg(target_os = "windows")]
2+
fn main() -> Result<(), Box<dyn std::error::Error>> {
3+
use std::sync::Arc;
4+
5+
use spdlog::{prelude::*, sink::WinDebugSink};
6+
7+
let sink = Arc::new(WinDebugSink::builder().build()?);
8+
let logger = spdlog::default_logger().fork_with(|logger| {
9+
logger.set_name(Some("demo")).unwrap();
10+
logger.sinks_mut().push(sink);
11+
Ok(())
12+
})?;
13+
spdlog::set_default_logger(logger);
14+
15+
info!("info message from spdlog-rs's WinDebugSink");
16+
error!("error message from spdlog-rs's WinDebugSink", kv: { error_code = 114514 });
17+
Ok(())
18+
}
19+
20+
#[cfg(not(target_os = "windows"))]
21+
fn main() {
22+
panic!("this example is only available on Windows target");
23+
}

0 commit comments

Comments
 (0)