Update to version 1.0.0

This commit is contained in:
ElBe
2023-10-24 09:33:46 +02:00
commit 0dcaf740aa
40 changed files with 1864 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
// logging-rs error tests
// Version: 1.0.0
// Copyright (c) 2023-present ElBe Development.
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the 'Software'),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
////////////////////////////////
// IMPORTS AND USE STATEMENTS //
////////////////////////////////
#[allow(unused_imports)]
use logging_rs;
///////////
// TESTS //
///////////
#[cfg(test)]
mod tests {
#[test]
fn test_error() {
let error: logging_rs::errors::Error =
logging_rs::errors::Error::new("name", "description", 1);
assert_eq!(
error,
logging_rs::errors::Error {
name: "name".to_owned(),
description: "description".to_owned(),
exit_code: 1
}
);
}
#[test]
#[ignore]
fn raise_helper() {
let error: logging_rs::errors::Error =
logging_rs::errors::Error::new("name", "description", 1);
error.raise("details");
}
#[test]
fn test_raise() {
let status = std::process::Command::new("cargo")
.args(&["test", "--", "--ignored"])
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.expect("Unable to run program");
assert_eq!(Some(1), status.code())
}
}
+113
View File
@@ -0,0 +1,113 @@
// logging-rs tests
// Version: 1.0.0
// Copyright (c) 2023-present ElBe Development.
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the 'Software'),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
////////////////////////////////
// IMPORTS AND USE STATEMENTS //
////////////////////////////////
#[allow(unused_imports)]
use logging_rs;
///////////
// TESTS //
///////////
#[cfg(test)]
mod tests {
#[test]
fn test_level_default() {
assert_eq!(
logging_rs::Level::default(),
logging_rs::Level::DEBUG
);
}
#[test]
fn test_output_default() {
assert_eq!(
logging_rs::Output::default(),
logging_rs::Output::STDOUT
);
}
#[test]
fn test_formatter_default() {
assert_eq!(
logging_rs::Formatter::default(),
logging_rs::Formatter {
color_format_string: "[{{color.bright_blue}}{{timestamp}}{{end}}] [{{level}}] {{path}}: {{message}}".to_owned(),
format_string: "[{{timestamp}}] [{{level}}] {{path}}: {{message}}".to_owned(),
timestamp_format: "%Y-%m-%d %H:%M:%S".to_owned()
}
);
}
#[test]
fn test_formatter_new() {
assert_eq!(
logging_rs::Formatter::new(
"[{{color.bright_blue}}{{timestamp}}{{end}}] [{{level}}] {{path}}: {{message}}",
"[{{timestamp}}] [{{level}}] {{path}}: {{message}}",
"%Y-%m-%d %H:%M:%S"
),
logging_rs::Formatter {
color_format_string: "[{{color.bright_blue}}{{timestamp}}{{end}}] [{{level}}] {{path}}: {{message}}".to_owned(),
format_string: "[{{timestamp}}] [{{level}}] {{path}}: {{message}}".to_owned(),
timestamp_format: "%Y-%m-%d %H:%M:%S".to_owned()
}
);
}
#[test]
fn test_formatter_format() {
let formatter: logging_rs::Formatter = logging_rs::Formatter::default();
assert_eq!(
formatter.format(logging_rs::Output::default(), logging_rs::Level::default(), "Test", vec![]),
"[\x1b[94mTIMESTAMP\x1b[0m] [DEBUG] {{path}}: Test"
);
}
#[test]
fn test_logger_default() {
assert_eq!(
logging_rs::Logger::default(),
logging_rs::Logger {
formatter: logging_rs::Formatter::default(),
writable_list: vec![logging_rs::Output::STDOUT]
}
);
}
#[test]
fn test_logger_new() {
assert_eq!(
logging_rs::Logger::new(logging_rs::Formatter::default(), vec![logging_rs::Output::STDOUT]),
logging_rs::Logger {
formatter: logging_rs::Formatter::default(),
writable_list: vec![logging_rs::Output::STDOUT]
}
);
}
}