Skip to content

Commit

Permalink
Fix platform-specific EOL for test log_crate_proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Mar 21, 2024
1 parent c2f4edd commit 281f1aa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions spdlog/src/formatter/full_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cfg_if::cfg_if;

use crate::{
formatter::{FmtExtraInfo, Formatter, LOCAL_TIME_CACHER},
Error, Record, StringBuf, EOL,
Error, Record, StringBuf, __EOL,
};

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

if self.with_eol {
dest.write_str(EOL)?;
dest.write_str(__EOL)?;
}

Ok(FmtExtraInfo {
Expand Down Expand Up @@ -125,7 +125,7 @@ mod tests {
use chrono::prelude::*;

use super::*;
use crate::{Level, EOL};
use crate::{Level, __EOL};

#[test]
fn format() {
Expand All @@ -138,7 +138,7 @@ mod tests {
format!(
"[{}] [warn] test log content{}",
local_time.format("%Y-%m-%d %H:%M:%S.%3f"),
EOL
__EOL
),
buf
);
Expand Down
4 changes: 2 additions & 2 deletions spdlog/src/formatter/journald_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cfg_if::cfg_if;

use crate::{
formatter::{FmtExtraInfo, Formatter},
Error, Record, StringBuf, EOL,
Error, Record, StringBuf, __EOL,
};

#[derive(Clone)]
Expand Down Expand Up @@ -47,7 +47,7 @@ impl JournaldFormatter {

dest.write_str("] ")?;
dest.write_str(record.payload())?;
dest.write_str(EOL)?;
dest.write_str(__EOL)?;

Ok(FmtExtraInfo {
style_range: Some(style_range_begin..style_range_end),
Expand Down
2 changes: 1 addition & 1 deletion spdlog/src/formatter/pattern_formatter/pattern/eol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ impl Pattern for Eol {
dest: &mut StringBuf,
_ctx: &mut PatternContext,
) -> crate::Result<()> {
dest.write_str(crate::EOL).map_err(Error::FormatRecord)
dest.write_str(crate::__EOL).map_err(Error::FormatRecord)
}
}
6 changes: 4 additions & 2 deletions spdlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,11 @@ cfg_if! {
}

#[cfg(not(windows))]
pub(crate) const EOL: &str = "\n";
#[doc(hidden)]
pub const __EOL: &str = "\n";
#[cfg(windows)]
pub(crate) const EOL: &str = "\r\n";
#[doc(hidden)]
pub const __EOL: &str = "\r\n";

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

Expand Down
9 changes: 6 additions & 3 deletions spdlog/tests/log_crate_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::sync::{Arc, Mutex};

use spdlog::formatter::{pattern, PatternFormatter};
use spdlog::{
formatter::{pattern, PatternFormatter},
__EOL,
};

include!(concat!(
env!("OUT_DIR"),
Expand All @@ -27,7 +30,7 @@ fn test_source_location() {
log::info!("text");
assert_eq!(
sink.clone_string(),
"(log_crate_proxy::log_crate_proxy.rs) text\n"
format!("(log_crate_proxy::log_crate_proxy.rs) text{__EOL}")
);
}

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

log::info!(target: "MyLogger", "body");
assert_eq!(sink.clone_string(), "[MyLogger] body\n");
assert_eq!(sink.clone_string(), format!("[MyLogger] body{__EOL}"));
}
9 changes: 2 additions & 7 deletions spdlog/tests/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use spdlog::{
formatter::{pattern, Formatter, Pattern, PatternFormatter},
prelude::*,
sink::Sink,
StringBuf,
StringBuf, __EOL,
};

include!(concat!(
Expand Down Expand Up @@ -246,12 +246,7 @@ fn test_builtin_patterns() {
res = replace_substring(res, WEEKDAY_NAMES, "{weekday_name}");
res = replace_substring(res, MONTH_NAMES, "{month_name}");
res = replace_substring(res, AM_PM, "{am_pm}");

#[cfg(not(windows))]
const EOL: &str = "\n";
#[cfg(windows)]
const EOL: &str = "\r\n";
res = replace_substring(res, [EOL], "{eol}");
res = replace_substring(res, [__EOL], "{eol}");

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

0 comments on commit 281f1aa

Please sign in to comment.