Debian Codegraph @

debian/rust-vendor/codspeed-divan-compat-walltime/tests/entry_properties.rs

raw
1 // Tests that entry benchmarks/groups have correct generated properties.
2
3 // Miri cannot discover benchmarks.
4 #![cfg(not(miri))]
5
6 extern crate codspeed_divan_compat_walltime as divan;
7 use divan::__private::{EntryMeta, BENCH_ENTRIES, GROUP_ENTRIES};
8
9 #[divan::bench]
10 fn outer() {}
11
12 #[divan::bench_group]
13 mod outer_group {
14 #[divan::bench]
15 fn inner() {}
16
17 #[divan::bench_group]
18 mod inner_group {}
19 }
20
21 #[divan::bench]
22 #[ignore]
23 fn ignored_1() {}
24
25 #[divan::bench(ignore)]
26 fn ignored_2() {}
27
28 #[divan::bench_group]
29 #[allow(unused_attributes)]
30 #[ignore]
31 mod ignored_group {
32 #[divan::bench]
33 fn not_yet_ignored() {}
34 }
35
36 /// Finds `EntryMeta` based on the entry's raw name.
37 macro_rules! find_meta {
38 ($entries:expr, $raw_name:literal) => {
39 $entries
40 .iter()
41 .map(|entry| &entry.meta)
42 .find(|common| common.raw_name == $raw_name)
43 .expect(concat!($raw_name, " not found"))
44 };
45 }
46
47 fn find_outer() -> &'static EntryMeta {
48 find_meta!(BENCH_ENTRIES, "outer")
49 }
50
51 fn find_inner() -> &'static EntryMeta {
52 find_meta!(BENCH_ENTRIES, "inner")
53 }
54
55 fn find_outer_group() -> &'static EntryMeta {
56 find_meta!(GROUP_ENTRIES, "outer_group")
57 }
58
59 fn find_inner_group() -> &'static EntryMeta {
60 find_meta!(GROUP_ENTRIES, "inner_group")
61 }
62
63 #[test]
64 fn file() {
65 let file = file!();
66
67 assert_eq!(find_outer().location.file, file);
68 assert_eq!(find_outer_group().location.file, file);
69
70 assert_eq!(find_inner().location.file, file);
71 assert_eq!(find_inner_group().location.file, file);
72 }
73
74 #[test]
75 fn module_path() {
76 let outer_path = module_path!();
77 assert_eq!(find_outer().module_path, outer_path);
78 assert_eq!(find_outer_group().module_path, outer_path);
79
80 let inner_path = format!("{outer_path}::outer_group");
81 assert_eq!(find_inner().module_path, inner_path);
82 assert_eq!(find_inner_group().module_path, inner_path);
83 }
84
85 #[ignore = "changed within the fork"]
86 #[test]
87 fn line() {
88 assert_eq!(find_outer().location.line, 8);
89 assert_eq!(find_outer_group().location.line, 11);
90
91 assert_eq!(find_inner().location.line, 13);
92 assert_eq!(find_inner_group().location.line, 16);
93 }
94
95 #[test]
96 fn column() {
97 assert_eq!(find_outer().location.col, 1);
98 assert_eq!(find_outer_group().location.col, 1);
99
100 assert_eq!(find_inner().location.col, 5);
101 assert_eq!(find_inner_group().location.col, 5);
102 }
103
104 #[test]
105 fn ignore() {
106 fn get_ignore(meta: &EntryMeta) -> bool {
107 meta.bench_options.as_ref().and_then(|options| options.ignore).unwrap_or_default()
108 }
109
110 assert!(get_ignore(find_meta!(BENCH_ENTRIES, "ignored_1")));
111 assert!(get_ignore(find_meta!(BENCH_ENTRIES, "ignored_2")));
112 assert!(get_ignore(find_meta!(GROUP_ENTRIES, "ignored_group")));
113
114 // Although its parent is marked as `#[ignore]`, it itself is not yet known
115 // to be ignored.
116 assert!(!get_ignore(find_meta!(BENCH_ENTRIES, "not_yet_ignored")));
117
118 assert!(!get_ignore(find_inner()));
119 assert!(!get_ignore(find_inner_group()));
120 assert!(!get_ignore(find_outer()));
121 assert!(!get_ignore(find_outer_group()));
122 }