• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jtmoon79 / super-speedy-syslog-searcher / 20603980203

30 Dec 2025 07:10PM UTC coverage: 67.773% (-2.0%) from 69.779%
20603980203

push

github

jtmoon79
(CI) s4_* --venv

15621 of 23049 relevant lines covered (67.77%)

123479.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.43
/src/debug/printers.rs
1
// src/debug/printers.rs
2

3
//! A hodge-podge of printer functions and helpers for test and debug builds.
4

5
#[cfg(test)]
6
use std::io::prelude::*; // for `std::fs::File.read_to_string`
7
#[cfg(any(debug_assertions, test))]
8
use std::io::Write; // for `std::io::Stdout.flush`
9

10
#[doc(hidden)]
11
pub use ::termcolor::{
12
    Color,
13
    ColorChoice,
14
    ColorSpec,
15
    WriteColor,
16
};
17
#[doc(hidden)]
18
#[cfg(any(debug_assertions, test))]
19
use ::utf8_iter::Utf8CharsEx;
20

21
#[cfg(test)]
22
use crate::common::{
23
    FPath,
24
    FileOpenOptions,
25
}; // provides `.chars()` on `&[u8]`
26

27
/// `d`ebug `e`println! an `err`or
28
#[macro_export]
29
macro_rules! de_err {
30
    (
31
        $($args:tt)*
32
    ) => {
33
        {
34
            #[cfg(any(debug_assertions,test))]
35
            eprint!("ERROR: ");
36
            #[cfg(any(debug_assertions,test))]
37
            eprintln!($($args)*)
38
        }
39
    }
40
}
41
pub use de_err;
42

43
/// `d`ebug `e`println! an `warn`ing
44
#[macro_export]
45
macro_rules! de_wrn {
46
    (
47
        $($args:tt)*
48
    ) => {
49
        {
50
            #[cfg(any(debug_assertions,test))]
51
            eprint!("WARNING: ");
52
            #[cfg(any(debug_assertions,test))]
53
            eprintln!($($args)*)
54
        }
55
    }
56
}
57
pub use de_wrn;
58

59
/// `e`println! an `err`or
60
#[macro_export]
61
macro_rules! e_err {
62
    (
63
        $($args:tt)*
64
    ) => {
65
        {
66
            eprint!("ERROR: ");
67
            eprintln!($($args)*)
68
        }
69
    }
70
}
71
pub use e_err;
72

73
/// `e`println! a `warn`ing
74
#[macro_export]
75
macro_rules! e_wrn {
76
    (
77
        $($args:tt)*
78
    ) => {
79
        {
80
            eprint!("WARNING: ");
81
            eprintln!($($args)*)
82
        }
83
    }
84
}
85
pub use e_wrn;
86

87
// ------------------------------------------
88
// helper functions - various print and write
89

90
/// turn passed u8 into char, for any char values that are CLI formatting
91
/// instructions transform them to pictoral representations, e.g. '\n' returns a
92
/// pictoral unicode representation '␊'.
93
///
94
/// This is intended as an improvement of `fmt::Debug` display of `str` which
95
/// control codes with backslash-escape sequences, e.g. '\n'. This function
96
/// keeps the printing width of a control character to 1. This helps humans
97
/// visually review various debug outputs.
98
///
99
/// only intended to aid visual debugging
100
///
101
/// XXX: is this implemented in std or in a crate?
102
#[cfg(any(debug_assertions, test))]
103
pub const fn char_to_char_noraw(c: char) -> char {
290,473,947✔
104
    // https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0_controls
105
    match c as u32 {
290,473,947✔
106
        0 => '␀',
13,322,848✔
107
        1 => '␁',
1,460✔
108
        2 => '␂',
1,128✔
109
        3 => '␃',
478✔
110
        4 => '␄',
364✔
111
        5 => '␅',
1,272✔
112
        6 => '␆',
102✔
113
        7 => '␇',  // '\a'
2,913✔
114
        8 => '␈',  // '\b'
592✔
115
        9 => '␉',  // '\t'
1,362✔
116
        10 => '␊', // '\n'
19,560,846✔
117
        11 => '␋', // '\v'
139✔
118
        12 => '␌', // '\f'
610✔
119
        13 => '␍', // '\r'
358✔
120
        14 => '␎',
52✔
121
        15 => '␏',
271✔
122
        16 => '␐',
115✔
123
        17 => '␑',
×
124
        18 => '␒',
×
125
        19 => '␓',
×
126
        20 => '␔',
60✔
127
        21 => '␕',
6✔
128
        22 => '␖',
46✔
129
        23 => '␗',
×
130
        24 => '␘',
×
131
        25 => '␙',
20✔
132
        26 => '␚',
100✔
133
        27 => '␛', // '\e'
158✔
134
        28 => '␜',
83✔
135
        29 => '␝',
72✔
136
        30 => '␞',
434,276✔
137
        31 => '␟',
41✔
138
        127 => '␡',
60✔
139
        _ => c,
257,144,115✔
140
    }
141
}
290,473,947✔
142

143
/// transform utf-8 byte (presumably) to non-raw char
144
///
145
/// only intended for debugging
146
#[doc(hidden)]
147
#[cfg(any(debug_assertions, test))]
148
pub const fn byte_to_char_noraw(byte: u8) -> char {
1,116,717✔
149
    char_to_char_noraw(byte as char)
1,116,717✔
150
}
1,116,717✔
151

152
/// transform buffer of chars to a non-raw String
153
/// chars may be invalid utf-8
154
///
155
/// extremely inefficient!
156
/// only intended for debugging
157
#[doc(hidden)]
158
#[allow(non_snake_case)]
159
#[cfg(any(debug_assertions, test))]
160
pub fn buffer_to_String_noraw(buffer: &[u8]) -> String {
772,727✔
161
    let mut s2: String = String::with_capacity(buffer.len() + 1);
772,727✔
162
    for c in buffer.chars() {
271,643,699✔
163
        let c_: char = char_to_char_noraw(c);
271,643,699✔
164
        s2.push(c_);
271,643,699✔
165
    }
271,643,699✔
166
    s2
772,727✔
167
}
772,727✔
168

169
/// transform valid UTF8 str to non-raw String version
170
///
171
/// extremely inefficient
172
/// only intended for debugging
173
#[doc(hidden)]
174
#[allow(non_snake_case)]
175
#[cfg(any(debug_assertions, test))]
176
pub fn str_to_String_noraw(str_buf: &str) -> String {
74,191✔
177
    let mut s2 = String::with_capacity(str_buf.len() + 1);
74,191✔
178
    for c in str_buf.chars() {
1,627,686✔
179
        let c_ = char_to_char_noraw(c);
1,627,686✔
180
        s2.push(c_);
1,627,686✔
181
    }
1,627,686✔
182
    s2
74,191✔
183
}
74,191✔
184

185
/// return contents of file utf-8 chars (presumably) at `path` as non-raw String
186
///
187
/// extremely inefficient
188
/// only intended for debugging
189
#[allow(non_snake_case)]
190
#[cfg(test)]
191
pub fn file_to_String_noraw(path: &FPath) -> String {
×
192
    let path_ = std::path::Path::new(path);
×
193
    let mut open_options = FileOpenOptions::new();
×
194
    let mut file_ = match open_options
×
195
        .read(true)
×
196
        .open(path_)
×
197
    {
198
        Ok(val) => val,
×
199
        Err(err) => {
×
200
            eprintln!("ERROR: File::open('{:?}') error {}", path_, err);
×
201
            return String::with_capacity(0);
×
202
        }
203
    };
204
    let filesz = match file_.metadata() {
×
205
        Ok(val) => val.len() as usize,
×
206
        Err(err) => {
×
207
            eprintln!("ERROR: File::metadata() error {}", err);
×
208
            return String::with_capacity(0);
×
209
        }
210
    };
211
    let mut s2 = String::with_capacity(filesz + 1);
×
212
    let s2read = match file_.read_to_string(&mut s2) {
×
213
        Ok(val) => val,
×
214
        Err(err) => {
×
215
            eprintln!("ERROR: File::read_to_string() error {}", err);
×
216
            return String::with_capacity(0);
×
217
        }
218
    };
219
    assert_eq!(
×
220
        s2read, filesz,
221
        "Read {} bytes but expected to read file size count of bytes {} for file {:?}",
×
222
        s2read, filesz, path
223
    );
224
    let mut s3 = String::with_capacity(filesz + 1);
×
225
    for c in s2.chars() {
×
226
        let c_ = char_to_char_noraw(c);
×
227
        s3.push(c_);
×
228
    }
×
229

230
    s3
×
231
}
×
232

233
/// Helper flush stdout and stderr
234
#[doc(hidden)]
235
#[allow(dead_code)]
236
#[cfg(any(debug_assertions, test))]
237
pub fn flush_stdouterr() {
×
238
    #[allow(clippy::match_single_binding)]
239
    match std::io::stdout().flush() {
×
240
        _ => {}
×
241
    };
242
    #[allow(clippy::match_single_binding)]
243
    match std::io::stderr().flush() {
×
244
        _ => {}
×
245
    };
246
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc