summaryrefslogtreecommitdiffstats
path: root/vendor/env_logger/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /vendor/env_logger/tests
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/env_logger/tests')
-rw-r--r--vendor/env_logger/tests/init-twice-retains-filter.rs40
-rw-r--r--vendor/env_logger/tests/log-in-log.rs39
-rw-r--r--vendor/env_logger/tests/log_tls_dtors.rs66
-rw-r--r--vendor/env_logger/tests/regexp_filter.rs57
4 files changed, 202 insertions, 0 deletions
diff --git a/vendor/env_logger/tests/init-twice-retains-filter.rs b/vendor/env_logger/tests/init-twice-retains-filter.rs
new file mode 100644
index 000000000..673da3fd2
--- /dev/null
+++ b/vendor/env_logger/tests/init-twice-retains-filter.rs
@@ -0,0 +1,40 @@
+extern crate env_logger;
+extern crate log;
+
+use std::env;
+use std::process;
+use std::str;
+
+fn main() {
+ if env::var("YOU_ARE_TESTING_NOW").is_ok() {
+ // Init from the env (which should set the max level to `Debug`)
+ env_logger::init();
+
+ assert_eq!(log::LevelFilter::Debug, log::max_level());
+
+ // Init again using a different max level
+ // This shouldn't clobber the level that was previously set
+ env_logger::Builder::new()
+ .parse_filters("info")
+ .try_init()
+ .unwrap_err();
+
+ assert_eq!(log::LevelFilter::Debug, log::max_level());
+ return;
+ }
+
+ let exe = env::current_exe().unwrap();
+ let out = process::Command::new(exe)
+ .env("YOU_ARE_TESTING_NOW", "1")
+ .env("RUST_LOG", "debug")
+ .output()
+ .unwrap_or_else(|e| panic!("Unable to start child process: {}", e));
+ if out.status.success() {
+ return;
+ }
+
+ println!("test failed: {}", out.status);
+ println!("--- stdout\n{}", str::from_utf8(&out.stdout).unwrap());
+ println!("--- stderr\n{}", str::from_utf8(&out.stderr).unwrap());
+ process::exit(1);
+}
diff --git a/vendor/env_logger/tests/log-in-log.rs b/vendor/env_logger/tests/log-in-log.rs
new file mode 100644
index 000000000..89517ff36
--- /dev/null
+++ b/vendor/env_logger/tests/log-in-log.rs
@@ -0,0 +1,39 @@
+#[macro_use]
+extern crate log;
+extern crate env_logger;
+
+use std::env;
+use std::fmt;
+use std::process;
+use std::str;
+
+struct Foo;
+
+impl fmt::Display for Foo {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ info!("test");
+ f.write_str("bar")
+ }
+}
+
+fn main() {
+ env_logger::init();
+ if env::var("YOU_ARE_TESTING_NOW").is_ok() {
+ return info!("{}", Foo);
+ }
+
+ let exe = env::current_exe().unwrap();
+ let out = process::Command::new(exe)
+ .env("YOU_ARE_TESTING_NOW", "1")
+ .env("RUST_LOG", "debug")
+ .output()
+ .unwrap_or_else(|e| panic!("Unable to start child process: {}", e));
+ if out.status.success() {
+ return;
+ }
+
+ println!("test failed: {}", out.status);
+ println!("--- stdout\n{}", str::from_utf8(&out.stdout).unwrap());
+ println!("--- stderr\n{}", str::from_utf8(&out.stderr).unwrap());
+ process::exit(1);
+}
diff --git a/vendor/env_logger/tests/log_tls_dtors.rs b/vendor/env_logger/tests/log_tls_dtors.rs
new file mode 100644
index 000000000..5db87bd6c
--- /dev/null
+++ b/vendor/env_logger/tests/log_tls_dtors.rs
@@ -0,0 +1,66 @@
+#[macro_use]
+extern crate log;
+extern crate env_logger;
+
+use std::env;
+use std::process;
+use std::str;
+use std::thread;
+
+struct DropMe;
+
+impl Drop for DropMe {
+ fn drop(&mut self) {
+ debug!("Dropping now");
+ }
+}
+
+fn run() {
+ // Use multiple thread local values to increase the chance that our TLS
+ // value will get destroyed after the FORMATTER key in the library
+ thread_local! {
+ static DROP_ME_0: DropMe = DropMe;
+ static DROP_ME_1: DropMe = DropMe;
+ static DROP_ME_2: DropMe = DropMe;
+ static DROP_ME_3: DropMe = DropMe;
+ static DROP_ME_4: DropMe = DropMe;
+ static DROP_ME_5: DropMe = DropMe;
+ static DROP_ME_6: DropMe = DropMe;
+ static DROP_ME_7: DropMe = DropMe;
+ static DROP_ME_8: DropMe = DropMe;
+ static DROP_ME_9: DropMe = DropMe;
+ }
+ DROP_ME_0.with(|_| {});
+ DROP_ME_1.with(|_| {});
+ DROP_ME_2.with(|_| {});
+ DROP_ME_3.with(|_| {});
+ DROP_ME_4.with(|_| {});
+ DROP_ME_5.with(|_| {});
+ DROP_ME_6.with(|_| {});
+ DROP_ME_7.with(|_| {});
+ DROP_ME_8.with(|_| {});
+ DROP_ME_9.with(|_| {});
+}
+
+fn main() {
+ env_logger::init();
+ if env::var("YOU_ARE_TESTING_NOW").is_ok() {
+ // Run on a separate thread because TLS values on the main thread
+ // won't have their destructors run if pthread is used.
+ // https://doc.rust-lang.org/std/thread/struct.LocalKey.html#platform-specific-behavior
+ thread::spawn(run).join().unwrap();
+ } else {
+ let exe = env::current_exe().unwrap();
+ let out = process::Command::new(exe)
+ .env("YOU_ARE_TESTING_NOW", "1")
+ .env("RUST_LOG", "debug")
+ .output()
+ .unwrap_or_else(|e| panic!("Unable to start child process: {}", e));
+ if !out.status.success() {
+ println!("test failed: {}", out.status);
+ println!("--- stdout\n{}", str::from_utf8(&out.stdout).unwrap());
+ println!("--- stderr\n{}", str::from_utf8(&out.stderr).unwrap());
+ process::exit(1);
+ }
+ }
+}
diff --git a/vendor/env_logger/tests/regexp_filter.rs b/vendor/env_logger/tests/regexp_filter.rs
new file mode 100644
index 000000000..40178bac7
--- /dev/null
+++ b/vendor/env_logger/tests/regexp_filter.rs
@@ -0,0 +1,57 @@
+#[macro_use]
+extern crate log;
+extern crate env_logger;
+
+use std::env;
+use std::process;
+use std::str;
+
+fn main() {
+ if env::var("LOG_REGEXP_TEST").ok() == Some(String::from("1")) {
+ child_main();
+ } else {
+ parent_main()
+ }
+}
+
+fn child_main() {
+ env_logger::init();
+ info!("XYZ Message");
+}
+
+fn run_child(rust_log: String) -> bool {
+ let exe = env::current_exe().unwrap();
+ let out = process::Command::new(exe)
+ .env("LOG_REGEXP_TEST", "1")
+ .env("RUST_LOG", rust_log)
+ .output()
+ .unwrap_or_else(|e| panic!("Unable to start child process: {}", e));
+ str::from_utf8(out.stderr.as_ref())
+ .unwrap()
+ .contains("XYZ Message")
+}
+
+fn assert_message_printed(rust_log: &str) {
+ if !run_child(rust_log.to_string()) {
+ panic!("RUST_LOG={} should allow the test log message", rust_log)
+ }
+}
+
+fn assert_message_not_printed(rust_log: &str) {
+ if run_child(rust_log.to_string()) {
+ panic!(
+ "RUST_LOG={} should not allow the test log message",
+ rust_log
+ )
+ }
+}
+
+fn parent_main() {
+ // test normal log severity levels
+ assert_message_printed("info");
+ assert_message_not_printed("warn");
+
+ // test of regular expression filters
+ assert_message_printed("info/XYZ");
+ assert_message_not_printed("info/XXX");
+}