comparison libpam-sys/libpam-sys-test/build.rs @ 124:f469b8d9ad78 default tip

Add tests for the original X/SSO constants list.
author Paul Fisher <paul@pfish.zone>
date Mon, 30 Jun 2025 04:54:38 -0400
parents 9e05e44050d0
children
comparison
equal deleted inserted replaced
123:98a624cacd82 124:f469b8d9ad78
7 7
8 fn main() { 8 fn main() {
9 let config = match PamImpl::CURRENT { 9 let config = match PamImpl::CURRENT {
10 PamImpl::LinuxPam => TestConfig { 10 PamImpl::LinuxPam => TestConfig {
11 headers: vec![ 11 headers: vec![
12 "security/_pam_types.h".into(), 12 "<security/_pam_types.h>",
13 "security/pam_appl.h".into(), 13 "<security/pam_appl.h>",
14 "security/pam_ext.h".into(), 14 "<security/pam_ext.h>",
15 "security/pam_modules.h".into(), 15 "<security/pam_modules.h>",
16 ], 16 ],
17 ignore_consts: vec![ 17 ignore_consts: vec![
18 "__LINUX_PAM__".into(), 18 "__LINUX_PAM__",
19 "__LINUX_PAM_MINOR__".into(), 19 "__LINUX_PAM_MINOR__",
20 "PAM_AUTHTOK_RECOVER_ERR".into(), 20 "PAM_AUTHTOK_RECOVER_ERR",
21 ], 21 ],
22 ..Default::default() 22 ..Default::default()
23 }, 23 },
24 PamImpl::OpenPam => TestConfig { 24 PamImpl::OpenPam => TestConfig {
25 headers: vec![ 25 headers: vec![
26 "security/pam_types.h".into(), 26 "<security/pam_types.h>",
27 "security/openpam.h".into(), 27 "<security/openpam.h>",
28 "security/pam_appl.h".into(), 28 "<security/pam_appl.h>",
29 "security/pam_constants.h".into(), 29 "<security/pam_constants.h>",
30 ], 30 ],
31 ignore_consts: vec![ 31 ignore_consts: vec!["OPENPAM_VERSION", "OPENPAM_RELEASE", "PAM_SOEXT"],
32 "OPENPAM_VERSION".into(),
33 "OPENPAM_RELEASE".into(),
34 "PAM_SOEXT".into(),
35 ],
36 ..Default::default() 32 ..Default::default()
37 }, 33 },
38 PamImpl::Sun => TestConfig { 34 PamImpl::Sun => TestConfig {
39 headers: vec![ 35 headers: vec!["<security/pam_appl.h>", "<security/pam_modules.h>"],
40 "security/pam_appl.h".into(), 36 block_headers: vec!["sys/.*"],
41 "security/pam_modules.h".into(),
42 ],
43 block_headers: vec!["sys/.*".into()],
44 ..Default::default() 37 ..Default::default()
45 }, 38 },
46 PamImpl::XSso => Default::default(), 39 PamImpl::XSso => TestConfig {
40 headers: vec!["\"xsso_constants.h\""],
41 ignore_consts: vec!["PAM_CRED_PRELIM_CHECK"],
42 ..Default::default()
43 },
47 other => panic!("Unknown PAM implementation {other:?}"), 44 other => panic!("Unknown PAM implementation {other:?}"),
48 }; 45 };
49 generate_const_test(&config); 46 generate_const_test(&config);
50 } 47 }
51 48
98 .unwrap(); 95 .unwrap();
99 } 96 }
100 97
101 #[derive(Default)] 98 #[derive(Default)]
102 struct TestConfig { 99 struct TestConfig {
103 headers: Vec<String>, 100 headers: Vec<&'static str>,
104 block_headers: Vec<String>, 101 block_headers: Vec<&'static str>,
105 ignore_consts: Vec<String>, 102 ignore_consts: Vec<&'static str>,
106 } 103 }
107 104
108 impl TestConfig { 105 impl TestConfig {
109 fn header_contents(&self) -> String { 106 fn header_contents(&self) -> String {
110 let vec: Vec<_> = self 107 let vec: Vec<_> = self
111 .headers 108 .headers
112 .iter() 109 .iter()
113 .map(|h| format!("#include <{h}>\n")) 110 .map(|h| format!("#include {h}\n"))
114 .collect(); 111 .collect();
115 vec.join("") 112 vec.join("")
116 } 113 }
117 114
118 fn should_check_const(&self, item: &ItemConst) -> bool { 115 fn should_check_const(&self, item: &ItemConst) -> bool {
119 !self.ignore_consts.contains(&item.ident.to_string()) 116 !self
117 .ignore_consts
118 .contains(&item.ident.to_string().as_ref())
120 } 119 }
121 } 120 }