1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Tests for the `SPARSEIR_DEBUG` predicate.
//!
//! These call the pure predicate instead of setting `SPARSEIR_DEBUG`: the
//! process environment is shared with the tests running in parallel.
use super::enables_debug;
use std::ffi::OsStr;
fn enables(value: &str) -> bool {
enables_debug(Some(OsStr::new(value)))
}
/// pylibsparseir enables debug output when
/// `os.environ.get("SPARSEIR_DEBUG", "").lower() in ("1", "true", "yes", "on")`.
#[test]
fn test_accepted_values_enable_debug() {
for value in [
"1", "true", "TRUE", "True", "tRuE", "yes", "YES", "Yes", "on", "ON", "On",
] {
assert!(
enables(value),
"SPARSEIR_DEBUG={:?} must enable debug output",
value
);
}
}
#[test]
fn test_other_values_disable_debug() {
for value in [
// Falsy spellings, including the "0" that enabled output before
"",
"0",
"false",
"FALSE",
"no",
"off",
// Other numbers and abbreviations
"2",
"01",
"-1",
"t",
"y",
"enable",
"debug",
// Accepted values with extra characters (Python does not strip)
" 1",
"1 ",
" true",
"true\n",
"yes please",
"on,",
// Non-ASCII look-alikes (fullwidth forms)
"\u{FF11}",
"\u{FF34}\u{FF32}\u{FF35}\u{FF25}",
] {
assert!(
!enables(value),
"SPARSEIR_DEBUG={:?} must not enable debug output",
value
);
}
}
#[test]
fn test_unset_variable_disables_debug() {
assert!(!enables_debug(None));
}
#[cfg(unix)]
#[test]
fn test_non_unicode_value_disables_debug() {
use std::os::unix::ffi::OsStrExt;
for bytes in [&b"\xff"[..], &b"1\xff"[..], &b"on\x80"[..]] {
assert!(
!enables_debug(Some(OsStr::from_bytes(bytes))),
"SPARSEIR_DEBUG={:?} must not enable debug output",
bytes
);
}
}