1
#[allow(unused_imports)]
2
pub use super::*;
3
#[cfg(test)]
4
mod tests {
5
    use super::ProfileFlags;
6

            
7
    #[test]
8
1
    fn parse_single_token() {
9
1
        let f = ProfileFlags::parse("cpu");
10
1
        assert!(f.cpu && !f.memory && !f.heap);
11
1
    }
12

            
13
    #[test]
14
1
    fn parse_multiple_tokens() {
15
1
        let f = ProfileFlags::parse("heap,jsonl,detail");
16
1
        assert!(f.heap && f.jsonl && f.detail);
17
1
        assert!(!f.cpu && !f.memory);
18
1
    }
19

            
20
    #[test]
21
1
    fn parse_is_case_insensitive_and_trims() {
22
1
        let f = ProfileFlags::parse(" Heap , JSONL ");
23
1
        assert!(f.heap && f.jsonl);
24
1
    }
25

            
26
    #[test]
27
1
    fn parse_ignores_unknown_tokens() {
28
1
        let f = ProfileFlags::parse("cpu,bogus,heap");
29
1
        assert!(f.cpu && f.heap);
30
1
    }
31

            
32
    #[test]
33
1
    fn parse_accepts_aliases() {
34
1
        let f = ProfileFlags::parse("mem,perf,css");
35
1
        assert!(f.memory && f.cpu && f.cascade);
36
1
    }
37
}
38

            
39
#[cfg(test)]
40
#[allow(clippy::bool_assert_comparison)]
41
mod autotest_generated {
42
    use alloc::{
43
        string::{String, ToString},
44
        vec::Vec,
45
    };
46

            
47
    use super::*;
48

            
49
    // ---- helpers ---------------------------------------------------------
50

            
51
    /// Canonical token for every flag, in field-declaration order.
52
    const CANONICAL: [&str; 6] = ["memory", "cpu", "cascade", "heap", "jsonl", "detail"];
53

            
54
    /// The documented aliases, paired with the canonical token they mean.
55
    const ALIASES: [(&str, &str); 3] = [("mem", "memory"), ("perf", "cpu"), ("css", "cascade")];
56

            
57
    /// Read field `idx` of a flag set, indices matching `CANONICAL`.
58
    fn field(f: &ProfileFlags, idx: usize) -> bool {
59
        match idx {
60
            0 => f.memory,
61
            1 => f.cpu,
62
            2 => f.cascade,
63
            3 => f.heap,
64
            4 => f.jsonl,
65
            5 => f.detail,
66
            _ => unreachable!("CANONICAL has 6 entries"),
67
        }
68
    }
69

            
70
    /// Inverse of `ProfileFlags::parse`: render a flag set as an `AZ_PROFILE`
71
    /// value. Used for the encode/decode round-trip below.
72
    fn encode(f: ProfileFlags) -> String {
73
        let mut parts: Vec<&str> = Vec::new();
74
        if f.memory {
75
            parts.push("memory");
76
        }
77
        if f.cpu {
78
            parts.push("cpu");
79
        }
80
        if f.cascade {
81
            parts.push("cascade");
82
        }
83
        if f.heap {
84
            parts.push("heap");
85
        }
86
        if f.jsonl {
87
            parts.push("jsonl");
88
        }
89
        if f.detail {
90
            parts.push("detail");
91
        }
92
        parts.join(",")
93
    }
94

            
95
    /// Build a flag set from a 6-bit mask (bit i == field i in `CANONICAL`).
96
    fn from_mask(mask: u8) -> ProfileFlags {
97
        ProfileFlags {
98
            memory: mask & 0b00_0001 != 0,
99
            cpu: mask & 0b00_0010 != 0,
100
            cascade: mask & 0b00_0100 != 0,
101
            heap: mask & 0b00_1000 != 0,
102
            jsonl: mask & 0b01_0000 != 0,
103
            detail: mask & 0b10_0000 != 0,
104
        }
105
    }
106

            
107
    fn any_set(f: &ProfileFlags) -> bool {
108
        f.memory || f.cpu || f.cascade || f.heap || f.jsonl || f.detail
109
    }
110

            
111
    /// Core soundness invariant: a flag can only be set if the token that
112
    /// enables it literally occurs in the input (ASCII-case-insensitively).
113
    /// `parse` never invents flags out of thin air.
114
    fn assert_flags_are_justified(input: &str, f: &ProfileFlags) {
115
        let lower = input.to_ascii_lowercase();
116
        if f.memory {
117
            assert!(lower.contains("memory") || lower.contains("mem"));
118
        }
119
        if f.cpu {
120
            assert!(lower.contains("cpu") || lower.contains("perf"));
121
        }
122
        if f.cascade {
123
            assert!(lower.contains("cascade") || lower.contains("css"));
124
        }
125
        if f.heap {
126
            assert!(lower.contains("heap"));
127
        }
128
        if f.jsonl {
129
            assert!(lower.contains("jsonl"));
130
        }
131
        if f.detail {
132
            assert!(lower.contains("detail"));
133
        }
134
    }
135

            
136
    // ---- parser: empty / whitespace / separators -------------------------
137

            
138
    #[test]
139
    fn parse_empty_input_is_all_off() {
140
        assert_eq!(ProfileFlags::parse(""), ProfileFlags::default());
141
        assert!(!any_set(&ProfileFlags::parse("")));
142
    }
143

            
144
    #[test]
145
    fn parse_whitespace_only_is_all_off() {
146
        for input in [
147
            " ",
148
            "   ",
149
            "\t",
150
            "\n",
151
            "\r\n",
152
            "\t\n",
153
            " \t\r\n\x0c ",
154
            "\u{a0}",   // NBSP (Unicode White_Space)
155
            "\u{2003}", // EM SPACE
156
            "\u{3000}", // IDEOGRAPHIC SPACE
157
        ] {
158
            let f = ProfileFlags::parse(input);
159
            assert_eq!(f, ProfileFlags::default(), "input {input:?} set a flag");
160
        }
161
    }
162

            
163
    #[test]
164
    fn parse_separators_only_is_all_off() {
165
        for input in [",", ",,", ",,,,,,,,,,", " , , ", "\t,\n,\r", ",,cpu,,"] {
166
            let f = ProfileFlags::parse(input);
167
            assert_eq!(f.memory, false);
168
            assert_eq!(f.cascade, false);
169
            assert_eq!(f.heap, false);
170
            assert_eq!(f.jsonl, false);
171
            assert_eq!(f.detail, false);
172
        }
173
        // ...but real tokens surrounded by empty ones still register.
174
        assert!(ProfileFlags::parse(",,cpu,,").cpu);
175
        assert!(!ProfileFlags::parse(",,,,").cpu);
176
    }
177

            
178
    // ---- parser: garbage / junk ------------------------------------------
179

            
180
    #[test]
181
    fn parse_garbage_never_panics_and_sets_nothing() {
182
        for input in [
183
            "\0",
184
            "\0\0\0",
185
            "cpu\0", // NUL is not whitespace -> not trimmed -> no match
186
            "%s%n%s%n",
187
            "../../etc/passwd",
188
            "{\"cpu\":true}",
189
            "-1",
190
            "--cpu",
191
            "cpu=1",
192
            "cpu=true",
193
            "CPU;HEAP", // ';' is not a separator
194
            "cpu heap", // ' ' is not a separator
195
            "cpu\tjsonl",
196
            "cpux",
197
            "xcpu",
198
            "cp",
199
            "c,p,u",
200
            "\u{7f}\u{1}\u{2}",
201
            "\\x63\\x70\\x75",
202
        ] {
203
            let f = ProfileFlags::parse(input);
204
            assert_eq!(
205
                f,
206
                ProfileFlags::default(),
207
                "garbage input {input:?} should set no flags, got {f:?}"
208
            );
209
        }
210
    }
211

            
212
    #[test]
213
    fn parse_leading_trailing_junk_is_trimmed_or_rejected() {
214
        // Surrounding ASCII whitespace is trimmed -> token still matches.
215
        assert!(ProfileFlags::parse("  cpu  ").cpu);
216
        assert!(ProfileFlags::parse("\t\ncpu\r\n").cpu);
217
        assert!(ProfileFlags::parse("  heap ,  jsonl  ").heap);
218
        assert!(ProfileFlags::parse("  heap ,  jsonl  ").jsonl);
219

            
220
        // Non-whitespace junk glued to the token is *not* stripped: the token
221
        // must match exactly, so "valid;garbage" is rejected wholesale.
222
        assert_eq!(ProfileFlags::parse("cpu;garbage"), ProfileFlags::default());
223
        assert_eq!(ProfileFlags::parse("garbage;cpu"), ProfileFlags::default());
224
        assert_eq!(ProfileFlags::parse("'cpu'"), ProfileFlags::default());
225
        assert_eq!(ProfileFlags::parse("\"cpu\""), ProfileFlags::default());
226

            
227
        // ...but a junk *token* next to a valid token only kills itself.
228
        let f = ProfileFlags::parse("garbage,cpu,;;;,heap");
229
        assert!(f.cpu && f.heap);
230
        assert!(!f.memory && !f.cascade && !f.jsonl && !f.detail);
231
    }
232

            
233
    // ---- parser: numeric boundaries --------------------------------------
234

            
235
    #[test]
236
    fn parse_boundary_numeric_strings_are_ignored() {
237
        for input in [
238
            "0",
239
            "-0",
240
            "+0",
241
            "1",
242
            "9223372036854775807",  // i64::MAX
243
            "-9223372036854775808", // i64::MIN
244
            "9223372036854775808",  // i64::MAX + 1
245
            "18446744073709551615", // u64::MAX
246
            "18446744073709551616", // u64::MAX + 1
247
            "340282366920938463463374607431768211456",
248
            "1.7976931348623157e308", // f64::MAX
249
            "5e-324",                 // f64 min subnormal
250
            "1e309",                  // overflows to inf
251
            "NaN",
252
            "nan",
253
            "inf",
254
            "-inf",
255
            "infinity",
256
            "0x7fffffffffffffff",
257
            "0b1111",
258
            "1e",
259
            ".",
260
            "..",
261
        ] {
262
            let f = ProfileFlags::parse(input);
263
            assert_eq!(
264
                f,
265
                ProfileFlags::default(),
266
                "numeric-ish input {input:?} should set no flags, got {f:?}"
267
            );
268
        }
269
    }
270

            
271
    #[test]
272
    fn parse_numeric_tokens_mixed_with_valid_tokens_do_not_corrupt_flags() {
273
        let f = ProfileFlags::parse("NaN,cpu,inf,-0,9223372036854775807,heap,1e309");
274
        assert!(f.cpu && f.heap);
275
        assert!(!f.memory && !f.cascade && !f.jsonl && !f.detail);
276
    }
277

            
278
    // ---- parser: size / nesting limits -----------------------------------
279

            
280
    #[test]
281
    fn parse_extremely_long_single_token_does_not_panic_or_hang() {
282
        let huge: String = std::iter::repeat_n('a', 1_000_000).collect();
283
        assert_eq!(ProfileFlags::parse(&huge), ProfileFlags::default());
284

            
285
        // A 1M-char token that *starts* with a valid token must still not match
286
        // (exact equality, not prefix matching).
287
        let mut prefixed = String::from("cpu");
288
        prefixed.push_str(&huge);
289
        assert_eq!(ProfileFlags::parse(&prefixed), ProfileFlags::default());
290
    }
291

            
292
    #[test]
293
    fn parse_million_separators_does_not_panic_or_hang() {
294
        let commas: String = std::iter::repeat_n(',', 1_000_000).collect();
295
        assert_eq!(ProfileFlags::parse(&commas), ProfileFlags::default());
296

            
297
        // 1M empty tokens with one real token buried at the end.
298
        let mut with_token = commas.clone();
299
        with_token.push_str("cpu");
300
        assert!(ProfileFlags::parse(&with_token).cpu);
301
    }
302

            
303
    #[test]
304
    fn parse_repeated_token_250k_times_is_idempotent() {
305
        let repeated = "cpu,".repeat(250_000);
306
        let f = ProfileFlags::parse(&repeated);
307
        assert!(f.cpu);
308
        // Repetition is a union, never a toggle: parsing "cpu" 250k times is
309
        // the same as parsing it once.
310
        assert_eq!(f, ProfileFlags::parse("cpu"));
311
    }
312

            
313
    #[test]
314
    fn parse_deeply_nested_brackets_does_not_stack_overflow() {
315
        let depth = 10_000;
316
        let mut nested = String::new();
317
        for _ in 0..depth {
318
            nested.push('[');
319
        }
320
        nested.push_str("cpu");
321
        for _ in 0..depth {
322
            nested.push(']');
323
        }
324
        // Not a recursive-descent grammar: no recursion, no overflow, and the
325
        // bracket-wrapped token does not match.
326
        assert_eq!(ProfileFlags::parse(&nested), ProfileFlags::default());
327

            
328
        // Same depth, but comma-separated so every bracket is its own token.
329
        let nested_csv = "[,".repeat(depth);
330
        assert_eq!(ProfileFlags::parse(&nested_csv), ProfileFlags::default());
331
    }
332

            
333
    #[test]
334
    fn parse_many_distinct_unknown_tokens_does_not_hang() {
335
        let mut s = String::new();
336
        for i in 0..100_000u32 {
337
            s.push_str(&i.to_string());
338
            s.push(',');
339
        }
340
        s.push_str("detail");
341
        let f = ProfileFlags::parse(&s);
342
        assert!(f.detail);
343
        assert!(!f.cpu && !f.memory && !f.cascade && !f.heap && !f.jsonl);
344
    }
345

            
346
    // ---- parser: unicode --------------------------------------------------
347

            
348
    #[test]
349
    fn parse_unicode_does_not_panic_and_matches_exactly() {
350
        // Multibyte junk: never matches, never panics on a char boundary.
351
        for input in [
352
            "\u{1F600}", // emoji
353
            "\u{1F600},\u{1F4A9}",
354
            "cpu\u{301}", // "cpu" + combining acute -> different token
355
            "\u{301}cpu",
356
            "\u{feff}cpu", // BOM is NOT Unicode White_Space -> not trimmed
357
            "cpu",      // fullwidth latin
358
            "СРU",         // Cyrillic С/Р homoglyphs
359
            "cpü",
360
            "HEAP",
361
            "日本語,中文,한국어",
362
            "\u{202e}cpu", // RTL override
363
            "e\u{301}\u{301}\u{301}",
364
        ] {
365
            let f = ProfileFlags::parse(input);
366
            assert_eq!(
367
                f,
368
                ProfileFlags::default(),
369
                "unicode input {input:?} should set no flags, got {f:?}"
370
            );
371
        }
372
    }
373

            
374
    #[test]
375
    fn parse_trims_unicode_whitespace_around_ascii_tokens() {
376
        // `str::trim` uses the Unicode White_Space property, so NBSP / EM SPACE
377
        // / IDEOGRAPHIC SPACE are stripped just like ASCII spaces.
378
        assert!(ProfileFlags::parse("\u{a0}cpu\u{a0}").cpu);
379
        assert!(ProfileFlags::parse("\u{2003}heap\u{2003}").heap);
380
        assert!(ProfileFlags::parse("\u{3000}jsonl").jsonl);
381
    }
382

            
383
    #[test]
384
    fn parse_unicode_mixed_with_valid_tokens_keeps_valid_ones() {
385
        let f = ProfileFlags::parse("\u{1F600},cpu,日本語,heap,\u{202e}");
386
        assert!(f.cpu && f.heap);
387
        assert!(!f.memory && !f.cascade && !f.jsonl && !f.detail);
388
    }
389

            
390
    // ---- parser: positive controls & invariants ---------------------------
391

            
392
    #[test]
393
    fn parse_each_canonical_token_sets_exactly_one_flag() {
394
        for (idx, tok) in CANONICAL.iter().enumerate() {
395
            let f = ProfileFlags::parse(tok);
396
            assert!(field(&f, idx), "token {tok:?} did not set its own flag");
397
            let leaked = (0..CANONICAL.len())
398
                .filter(|other| *other != idx)
399
                .filter(|other| field(&f, *other))
400
                .count();
401
            assert_eq!(leaked, 0, "token {tok:?} leaked into another flag: {f:?}");
402
        }
403
    }
404

            
405
    #[test]
406
    fn parse_each_alias_is_equivalent_to_its_canonical_token() {
407
        for (alias, canonical) in ALIASES {
408
            assert_eq!(
409
                ProfileFlags::parse(alias),
410
                ProfileFlags::parse(canonical),
411
                "alias {alias:?} != canonical {canonical:?}"
412
            );
413
        }
414
    }
415

            
416
    #[test]
417
    fn parse_is_case_insensitive_for_every_token() {
418
        for (idx, tok) in CANONICAL.iter().enumerate() {
419
            for variant in [tok.to_ascii_uppercase(), tok.to_ascii_lowercase()] {
420
                let f = ProfileFlags::parse(&variant);
421
                assert!(field(&f, idx), "case variant {variant:?} did not match");
422
            }
423
        }
424
        let all = ProfileFlags::parse("MEMORY,CPU,CaScAdE,HeAp,jSoNl,DETAIL");
425
        assert_eq!(all, from_mask(0b11_1111));
426
    }
427

            
428
    #[test]
429
    fn parse_is_order_independent() {
430
        let a = ProfileFlags::parse("cpu,heap,detail");
431
        let b = ProfileFlags::parse("detail,heap,cpu");
432
        let c = ProfileFlags::parse("heap,detail,cpu");
433
        assert_eq!(a, b);
434
        assert_eq!(b, c);
435
    }
436

            
437
    #[test]
438
    fn parse_is_monotone_unknown_tokens_never_unset_a_flag() {
439
        let base = ProfileFlags::parse("cpu,heap");
440
        for junk in ["bogus", "", "   ", "\u{1F600}", "NaN", "-cpu", "heap;"] {
441
            let mut with_junk = String::from("cpu,heap,");
442
            with_junk.push_str(junk);
443
            let f = ProfileFlags::parse(&with_junk);
444
            assert!(f.cpu && f.heap, "junk {junk:?} cleared a flag: {f:?}");
445
            assert_eq!(f, base, "junk {junk:?} changed the flag set");
446
        }
447
    }
448

            
449
    #[test]
450
    fn parse_jsonl_does_not_implicitly_enable_heap() {
451
        // The docs say `jsonl` "requires heap to do anything" — that dependency
452
        // is *not* enforced at parse time, and this test pins that down.
453
        let f = ProfileFlags::parse("jsonl");
454
        assert!(f.jsonl);
455
        assert!(!f.heap);
456

            
457
        // Same for `detail`, which layers on top of `heap`.
458
        let d = ProfileFlags::parse("detail");
459
        assert!(d.detail);
460
        assert!(!d.heap);
461
    }
462

            
463
    // ---- round-trip: encode == decode ------------------------------------
464

            
465
    #[test]
466
    fn round_trip_all_64_flag_combinations() {
467
        for mask in 0..64u8 {
468
            let original = from_mask(mask);
469
            let encoded = encode(original);
470
            let decoded = ProfileFlags::parse(&encoded);
471
            assert_eq!(
472
                decoded, original,
473
                "round-trip failed for mask {mask:#08b} (encoded {encoded:?})"
474
            );
475
        }
476
    }
477

            
478
    #[test]
479
    fn round_trip_survives_whitespace_and_case_mangling() {
480
        for mask in 0..64u8 {
481
            let original = from_mask(mask);
482
            let encoded = encode(original);
483
            // Re-render as " TOKEN , TOKEN " in upper case with padding.
484
            let mangled: Vec<String> = encoded
485
                .split(',')
486
                .filter(|s| !s.is_empty())
487
                .map(|t| {
488
                    let mut s = String::from("  ");
489
                    s.push_str(&t.to_ascii_uppercase());
490
                    s.push_str(" \t");
491
                    s
492
                })
493
                .collect();
494
            let decoded = ProfileFlags::parse(&mangled.join(","));
495
            assert_eq!(
496
                decoded, original,
497
                "mangled round-trip failed for {mask:#08b}"
498
            );
499
        }
500
    }
501

            
502
    #[test]
503
    fn round_trip_is_stable_under_re_encoding() {
504
        for mask in 0..64u8 {
505
            let f = from_mask(mask);
506
            let once = encode(f);
507
            let twice = encode(ProfileFlags::parse(&once));
508
            assert_eq!(once, twice, "encode is not a fixed point for {mask:#08b}");
509
        }
510
    }
511

            
512
    // ---- deterministic pseudo-random fuzz --------------------------------
513

            
514
    #[test]
515
    fn parse_fuzz_is_deterministic_and_never_invents_flags() {
516
        const PIECES: [&str; 24] = [
517
            "cpu",
518
            "CPU",
519
            "mem",
520
            "memory",
521
            "cascade",
522
            "css",
523
            "heap",
524
            "jsonl",
525
            "detail",
526
            "perf",
527
            ",",
528
            ";",
529
            " ",
530
            "\t",
531
            "\n",
532
            "",
533
            "x",
534
            "0",
535
            "NaN",
536
            "\u{1F600}",
537
            "\u{301}",
538
            "\u{a0}",
539
            "=",
540
            "-",
541
        ];
542

            
543
        // Fixed-seed LCG: no Math.random / wall-clock, fully reproducible.
544
        let mut state: u64 = 0x2545_F491_4F6C_DD1D;
545
        let mut next = move || {
546
            state = state
547
                .wrapping_mul(6_364_136_223_846_793_005)
548
                .wrapping_add(1_442_695_040_888_963_407);
549
            (state >> 33) as usize
550
        };
551

            
552
        for _ in 0..2_000 {
553
            let len = next() % 24;
554
            let mut input = String::new();
555
            for _ in 0..len {
556
                input.push_str(PIECES[next() % PIECES.len()]);
557
            }
558

            
559
            let f = ProfileFlags::parse(&input);
560
            // 1. deterministic
561
            assert_eq!(f, ProfileFlags::parse(&input), "parse is not deterministic");
562
            // 2. never sets a flag whose token isn't present
563
            assert_flags_are_justified(&input, &f);
564
            // 3. a completely token-free input never sets anything
565
            let lower = input.to_ascii_lowercase();
566
            if ![
567
                "memory", "mem", "cpu", "perf", "cascade", "css", "heap", "jsonl", "detail",
568
            ]
569
            .iter()
570
            .any(|t| lower.contains(t))
571
            {
572
                assert_eq!(f, ProfileFlags::default(), "flags set for {input:?}");
573
            }
574
        }
575
    }
576

            
577
    // ---- flags() / out_path() / predicates --------------------------------
578

            
579
    #[test]
580
    fn default_flags_are_all_off() {
581
        let d = ProfileFlags::default();
582
        assert!(!any_set(&d));
583
        assert_eq!(d, ProfileFlags::parse(""));
584
    }
585

            
586
    #[test]
587
    fn flags_is_cached_and_stable_across_calls() {
588
        // NOTE: the env var is deliberately *not* mutated here — `flags()` is a
589
        // process-wide `OnceLock` and tests run in parallel threads, so any
590
        // `set_var` would be both racy and useless after first access.
591
        let first = flags();
592
        for _ in 0..1_000 {
593
            assert_eq!(flags(), first, "flags() is not stable across calls");
594
        }
595
    }
596

            
597
    #[test]
598
    fn predicates_agree_with_flags() {
599
        let f = flags();
600
        assert_eq!(memory_enabled(), f.memory);
601
        assert_eq!(cpu_enabled(), f.cpu);
602
        assert_eq!(cascade_enabled(), f.cascade);
603
        assert_eq!(heap_enabled(), f.heap);
604
        assert_eq!(jsonl_enabled(), f.jsonl);
605
        assert_eq!(detail_enabled(), f.detail);
606
    }
607

            
608
    #[test]
609
    fn predicates_are_idempotent() {
610
        for _ in 0..100 {
611
            assert_eq!(memory_enabled(), memory_enabled());
612
            assert_eq!(cpu_enabled(), cpu_enabled());
613
            assert_eq!(cascade_enabled(), cascade_enabled());
614
            assert_eq!(heap_enabled(), heap_enabled());
615
            assert_eq!(jsonl_enabled(), jsonl_enabled());
616
            assert_eq!(detail_enabled(), detail_enabled());
617
        }
618
    }
619

            
620
    #[test]
621
    fn out_path_does_not_panic_and_is_cached() {
622
        let first = out_path();
623
        for _ in 0..100 {
624
            assert_eq!(out_path(), first, "out_path() is not stable across calls");
625
        }
626
        // If a path *is* configured it must be a real (possibly empty) &'static
627
        // str handed back from the same cached allocation every time.
628
        if let Some(p) = first {
629
            assert_eq!(out_path().map(str::as_ptr), Some(p.as_ptr()));
630
        }
631
    }
632

            
633
    /// `no_std` builds have no environment: profiling must be hard-off.
634
    #[cfg(not(feature = "std"))]
635
    #[test]
636
    fn nostd_profiling_is_always_off() {
637
        assert_eq!(flags(), ProfileFlags::default());
638
        assert_eq!(out_path(), None);
639
        assert!(!memory_enabled());
640
        assert!(!cpu_enabled());
641
        assert!(!cascade_enabled());
642
        assert!(!heap_enabled());
643
        assert!(!jsonl_enabled());
644
        assert!(!detail_enabled());
645
    }
646

            
647
    /// Under `std`, `flags()` must agree with whatever `AZ_PROFILE` said at
648
    /// first access — and, crucially, must keep agreeing even if the env var is
649
    /// later changed by some other part of the process (it is cached forever).
650
    #[cfg(feature = "std")]
651
    #[test]
652
    fn std_flags_match_env_or_default_and_never_change() {
653
        let observed = flags();
654
        let expected_now = std::env::var("AZ_PROFILE")
655
            .map(|v| ProfileFlags::parse(&v))
656
            .unwrap_or_default();
657
        // The cache is filled on first access; within one test binary the env
658
        // var is not mutated, so these must agree.
659
        assert_eq!(observed, expected_now);
660
        assert_eq!(flags(), observed);
661
    }
662
}