summaryrefslogtreecommitdiffstats
path: root/vendor/env_logger/tests/regexp_filter.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/env_logger/tests/regexp_filter.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/env_logger/tests/regexp_filter.rs')
-rw-r--r--vendor/env_logger/tests/regexp_filter.rs57
1 files changed, 57 insertions, 0 deletions
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");
+}