Mercurial > crates > nonstick
annotate libpam-sys/libpam-sys-test/build.rs @ 131:a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Wed, 02 Jul 2025 02:24:21 -0400 |
parents | 80c07e5ab22f |
children | 0b6a17f8c894 |
rev | line source |
---|---|
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
1 use bindgen::MacroTypeVariation; |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
124
diff
changeset
|
2 use libpam_sys_impls::__pam_impl_enum__; |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
127
diff
changeset
|
3 use proc_macro2::{Group, Ident, TokenStream, TokenTree}; |
113
178310336596
Fix up more constants, make things i32 rather than u32.
Paul Fisher <paul@pfish.zone>
parents:
111
diff
changeset
|
4 use quote::{format_ident, ToTokens}; |
127 | 5 use std::path::Path; |
6 use std::process::Command; | |
7 use std::str::FromStr; | |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
8 use std::{env, fs}; |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
9 use syn::{Item, ItemConst}; |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
10 |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
124
diff
changeset
|
11 // We're using the macro directly so we can match exhaustively. |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
124
diff
changeset
|
12 __pam_impl_enum__!(); |
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
124
diff
changeset
|
13 |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
14 const REDIR_FD: &str = "pam_modutil_redirect_fd"; |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
15 |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
16 fn main() { |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
17 let config = match PamImpl::CURRENT { |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
18 PamImpl::LinuxPam => TestConfig { |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
19 headers: vec![ |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
20 "<security/_pam_types.h>", |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
21 "<security/pam_appl.h>", |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
22 "<security/pam_ext.h>", |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
23 "<security/pam_modules.h>", |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
24 "<security/pam_modutil.h>", |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
25 ], |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
26 allow_types: vec![REDIR_FD], |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
27 ignore_consts: vec![ |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
28 "__LINUX_PAM__", |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
29 "__LINUX_PAM_MINOR__", |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
30 "PAM_AUTHTOK_RECOVER_ERR", |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
31 ], |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
32 ..Default::default() |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
33 }, |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
34 PamImpl::OpenPam => TestConfig { |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
35 headers: vec![ |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
36 "<security/pam_types.h>", |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
37 "<security/openpam.h>", |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
38 "<security/pam_appl.h>", |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
39 "<security/pam_constants.h>", |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
40 ], |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
41 ignore_consts: vec!["OPENPAM_VERSION", "OPENPAM_RELEASE", "PAM_SOEXT"], |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
42 ..Default::default() |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
43 }, |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
44 PamImpl::Sun => TestConfig { |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
45 headers: vec!["<security/pam_appl.h>", "<security/pam_modules.h>"], |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
46 ..Default::default() |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
47 }, |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
48 PamImpl::XSso => TestConfig { |
125
2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
Paul Fisher <paul@pfish.zone>
parents:
124
diff
changeset
|
49 headers: vec!["\"xsso_pam_appl.h\""], |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
50 ..Default::default() |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
51 }, |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
52 }; |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
53 generate_const_test(&config); |
127 | 54 generate_ctest(&config); |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
55 } |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
56 |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
57 fn generate_const_test(config: &TestConfig) { |
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
58 let mut builder = bindgen::Builder::default() |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
59 .header_contents("_.h", &config.header_contents()) |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
60 .merge_extern_blocks(true) |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
61 .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
62 .allowlist_var("(OPEN)?PAM_.*") |
114
93d423b65555
Ignore version-specific OpenPAM constants; generate signed ints.
Paul Fisher <paul@pfish.zone>
parents:
113
diff
changeset
|
63 .default_macro_constant_type(MacroTypeVariation::Signed); |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
64 |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
65 for &typ in config.allow_types.iter() { |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
66 builder = builder.allowlist_type(typ); |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
67 } |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
68 |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
69 let generated = builder.generate().unwrap(); |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
70 generated.write_to_file(test_file("bindgen.rs")).unwrap(); |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
71 let file = syn::parse_file(&generated.to_string()).unwrap(); |
127 | 72 let mut tests = vec![ |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
73 "\ |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
74 #[allow(dead_code, non_camel_case_types, non_upper_case_globals)] |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
75 mod generated { |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
76 include!(\"bindgen.rs\"); |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
77 } |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
78 #[allow(deprecated, overflowing_literals)] |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
79 fn main() { |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
80 " |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
81 .into(), |
127 | 82 format!( |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
83 "assert_eq!(libpam_sys::PamImpl::CURRENT, libpam_sys::PamImpl::{:?});", |
127 | 84 PamImpl::CURRENT |
85 ), | |
86 ]; | |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
87 tests.extend( |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
88 file.items |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
89 .iter() |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
90 .filter_map(|item| { |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
91 if let Item::Const(item) = item { |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
92 Some(item) |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
93 } else { |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
94 None |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
95 } |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
96 }) |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
97 .filter(|&item| config.should_check_const(item)) |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
98 .map(|item| { |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
99 let name = item.ident.to_string(); |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
100 if let Some(stripped) = name.strip_prefix(&format!("{REDIR_FD}_")) { |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
101 format!("assert_eq!(generated::{name} as i32, libpam_sys::{REDIR_FD}::{stripped}.into());") |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
102 } else { |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
103 format!("assert_eq!(generated::{name}, libpam_sys::{name});") |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
104 } |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
105 }), |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
106 ); |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
107 tests.push("}".into()); |
127 | 108 let const_test = test_file("constant_test.rs"); |
109 fs::write(&const_test, tests.join("\n")).unwrap(); | |
110 rustfmt(&const_test); | |
111 } | |
112 | |
113 fn generate_ctest(config: &TestConfig) { | |
114 let mut test = ctest::TestGenerator::new(); | |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
115 test.cfg("_hack_impl", Some(&format!("{:?}", PamImpl::CURRENT))); |
127 | 116 |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
117 for &header in config.headers.iter() { |
127 | 118 if header.starts_with('"') { |
119 test.include(env::var("CARGO_MANIFEST_DIR").unwrap()); | |
120 } | |
121 test.header(&header[1..header.len() - 1]); | |
122 } | |
123 // These are opaque structs. | |
124 test.skip_struct(|name| matches!(name, "pam_handle" | "AppData")); | |
125 test.skip_type(|name| matches!(name, "ConversationCallback" | "CleanupCallback")); | |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
126 test.type_name(|name, is_struct, is_union| { |
127 | 127 assert!(!is_union); // we scabbin' |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
128 match (name, is_struct) { |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
129 ("AppData", _) => "void".into(), |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
130 (REDIR_FD, _) => format!("enum {REDIR_FD}"), |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
131 ("passwd", _) => "struct passwd".into(), |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
132 ("group", _) => "struct group".into(), |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
133 ("spwd", _) => "struct spwd".into(), |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
134 (name, true) => format!("struct {name}"), |
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
135 (other, false) => other.into(), |
127 | 136 } |
137 }); | |
138 | |
139 // | |
140 // Welcome to THE HACK ZONE. | |
141 // | |
142 | |
143 // Define away constness because the various PAM implementations | |
144 // have different const annotations and this will surely drive you crazy. | |
145 test.define("const", Some("")); | |
146 | |
147 // Also replace all the `const`s with `mut`s in the ffi.rs file. | |
148 let file_contents = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/ffi.rs")); | |
149 let deconsted_file = test_file("ffi.rs"); | |
150 remove_consts(file_contents, &deconsted_file); | |
151 | |
152 test.generate(&deconsted_file, "ctest.rs"); | |
153 } | |
154 | |
155 fn remove_consts(file_contents: &str, out_file: impl AsRef<Path>) { | |
156 let deconstified = deconstify( | |
157 TokenStream::from_str(file_contents).unwrap(), | |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
127
diff
changeset
|
158 &format_ident!("mut"), |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
159 ) |
127 | 160 .to_string(); |
161 let out_file = out_file.as_ref(); | |
162 fs::write(out_file, deconstified).unwrap(); | |
163 rustfmt(out_file) | |
164 } | |
165 | |
166 fn rustfmt(file: impl AsRef<Path>) { | |
167 let status = Command::new(env!("CARGO")) | |
168 .args(["fmt", "--", file.as_ref().to_str().unwrap()]) | |
169 .status() | |
170 .unwrap(); | |
171 assert!(status.success(), "rustfmt exited with code {status}"); | |
172 } | |
173 | |
130
80c07e5ab22f
Transfer over (almost) completely to using libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
127
diff
changeset
|
174 fn deconstify(stream: TokenStream, mut_token: &Ident) -> TokenStream { |
127 | 175 TokenStream::from_iter(stream.into_iter().map(|token| { |
176 match token { | |
177 TokenTree::Group(g) => { | |
178 TokenTree::Group(Group::new(g.delimiter(), deconstify(g.stream(), mut_token))) | |
179 .into_token_stream() | |
180 } | |
181 TokenTree::Ident(id) if id == "const" => mut_token.into_token_stream(), | |
182 other => other.into_token_stream(), | |
183 } | |
184 })) | |
185 } | |
186 | |
187 fn test_file(name: impl AsRef<str>) -> String { | |
188 format!("{}/{}", env::var("OUT_DIR").unwrap(), name.as_ref()) | |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
189 } |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
190 |
121
397743cb70e2
Make libpam-sys-tests work on Illumos!
Paul Fisher <paul@pfish.zone>
parents:
118
diff
changeset
|
191 #[derive(Default)] |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
192 struct TestConfig { |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
193 headers: Vec<&'static str>, |
131
a632a8874131
Get all the Linux-PAM functions into libpam-sys, and get tests right.
Paul Fisher <paul@pfish.zone>
parents:
130
diff
changeset
|
194 allow_types: Vec<&'static str>, |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
195 ignore_consts: Vec<&'static str>, |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
196 } |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
197 |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
198 impl TestConfig { |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
199 fn header_contents(&self) -> String { |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
200 let vec: Vec<_> = self |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
201 .headers |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
202 .iter() |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
203 .map(|h| format!("#include {h}\n")) |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
204 .collect(); |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
205 vec.join("") |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
206 } |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
207 |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
208 fn should_check_const(&self, item: &ItemConst) -> bool { |
124
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
209 !self |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
210 .ignore_consts |
f469b8d9ad78
Add tests for the original X/SSO constants list.
Paul Fisher <paul@pfish.zone>
parents:
122
diff
changeset
|
211 .contains(&item.ident.to_string().as_ref()) |
110
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
212 } |
2346fd501b7a
Add tests for constants and do other macro niceties.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
213 } |