Skip to content

Commit 281f1aa

Browse files
committed
Fix platform-specific EOL for test log_crate_proxy
1 parent c2f4edd commit 281f1aa

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

spdlog/src/formatter/full_formatter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cfg_if::cfg_if;
66

77
use crate::{
88
formatter::{FmtExtraInfo, Formatter, LOCAL_TIME_CACHER},
9-
Error, Record, StringBuf, EOL,
9+
Error, Record, StringBuf, __EOL,
1010
};
1111

1212
#[rustfmt::skip]
@@ -95,7 +95,7 @@ impl FullFormatter {
9595
dest.write_str(record.payload())?;
9696

9797
if self.with_eol {
98-
dest.write_str(EOL)?;
98+
dest.write_str(__EOL)?;
9999
}
100100

101101
Ok(FmtExtraInfo {
@@ -125,7 +125,7 @@ mod tests {
125125
use chrono::prelude::*;
126126

127127
use super::*;
128-
use crate::{Level, EOL};
128+
use crate::{Level, __EOL};
129129

130130
#[test]
131131
fn format() {
@@ -138,7 +138,7 @@ mod tests {
138138
format!(
139139
"[{}] [warn] test log content{}",
140140
local_time.format("%Y-%m-%d %H:%M:%S.%3f"),
141-
EOL
141+
__EOL
142142
),
143143
buf
144144
);

spdlog/src/formatter/journald_formatter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cfg_if::cfg_if;
99

1010
use crate::{
1111
formatter::{FmtExtraInfo, Formatter},
12-
Error, Record, StringBuf, EOL,
12+
Error, Record, StringBuf, __EOL,
1313
};
1414

1515
#[derive(Clone)]
@@ -47,7 +47,7 @@ impl JournaldFormatter {
4747

4848
dest.write_str("] ")?;
4949
dest.write_str(record.payload())?;
50-
dest.write_str(EOL)?;
50+
dest.write_str(__EOL)?;
5151

5252
Ok(FmtExtraInfo {
5353
style_range: Some(style_range_begin..style_range_end),

spdlog/src/formatter/pattern_formatter/pattern/eol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ impl Pattern for Eol {
2222
dest: &mut StringBuf,
2323
_ctx: &mut PatternContext,
2424
) -> crate::Result<()> {
25-
dest.write_str(crate::EOL).map_err(Error::FormatRecord)
25+
dest.write_str(crate::__EOL).map_err(Error::FormatRecord)
2626
}
2727
}

spdlog/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ cfg_if! {
304304
}
305305

306306
#[cfg(not(windows))]
307-
pub(crate) const EOL: &str = "\n";
307+
#[doc(hidden)]
308+
pub const __EOL: &str = "\n";
308309
#[cfg(windows)]
309-
pub(crate) const EOL: &str = "\r\n";
310+
#[doc(hidden)]
311+
pub const __EOL: &str = "\r\n";
310312

311313
static DEFAULT_LOGGER: OnceCell<ArcSwap<Logger>> = OnceCell::new();
312314

spdlog/tests/log_crate_proxy.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::sync::{Arc, Mutex};
22

3-
use spdlog::formatter::{pattern, PatternFormatter};
3+
use spdlog::{
4+
formatter::{pattern, PatternFormatter},
5+
__EOL,
6+
};
47

58
include!(concat!(
69
env!("OUT_DIR"),
@@ -27,7 +30,7 @@ fn test_source_location() {
2730
log::info!("text");
2831
assert_eq!(
2932
sink.clone_string(),
30-
"(log_crate_proxy::log_crate_proxy.rs) text\n"
33+
format!("(log_crate_proxy::log_crate_proxy.rs) text{__EOL}")
3134
);
3235
}
3336

@@ -44,5 +47,5 @@ fn test_target() {
4447
log::set_max_level(log::LevelFilter::Trace);
4548

4649
log::info!(target: "MyLogger", "body");
47-
assert_eq!(sink.clone_string(), "[MyLogger] body\n");
50+
assert_eq!(sink.clone_string(), format!("[MyLogger] body{__EOL}"));
4851
}

spdlog/tests/pattern.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use spdlog::{
1111
formatter::{pattern, Formatter, Pattern, PatternFormatter},
1212
prelude::*,
1313
sink::Sink,
14-
StringBuf,
14+
StringBuf, __EOL,
1515
};
1616

1717
include!(concat!(
@@ -246,12 +246,7 @@ fn test_builtin_patterns() {
246246
res = replace_substring(res, WEEKDAY_NAMES, "{weekday_name}");
247247
res = replace_substring(res, MONTH_NAMES, "{month_name}");
248248
res = replace_substring(res, AM_PM, "{am_pm}");
249-
250-
#[cfg(not(windows))]
251-
const EOL: &str = "\n";
252-
#[cfg(windows)]
253-
const EOL: &str = "\r\n";
254-
res = replace_substring(res, [EOL], "{eol}");
249+
res = replace_substring(res, [__EOL], "{eol}");
255250

256251
if res.starts_with('+') || res.starts_with('-') {
257252
res.replace_range(0..1, "{begin_sign}");

0 commit comments

Comments
 (0)