testkit_macros/
lib.rs

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
#![deny(warnings)]
#![warn(unused_extern_crates)]
#![deny(clippy::todo)]
#![deny(clippy::unimplemented)]
#![deny(clippy::unwrap_used)]
#![deny(clippy::expect_used)]
#![deny(clippy::panic)]
#![deny(clippy::unreachable)]
#![deny(clippy::await_holding_lock)]
#![deny(clippy::needless_pass_by_value)]
#![deny(clippy::trivially_copy_pass_by_ref)]

mod entry;

#[allow(unused_extern_crates)]
extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;

#[proc_macro_attribute]
pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
    entry::test(args, item)
}

#[proc_macro]
/// used in testkit to build and run the kanidm binary with the correct environment variables
pub fn cli_kanidm(_input: TokenStream) -> TokenStream {
    let code = quote! {
        {
        // get the manifest path for the kanidm binary
        let cli_manifest_file_path =
            format!("{}/../../tools/cli/Cargo.toml", env!("CARGO_MANIFEST_DIR"));
        let cli_manifest_file = std::path::Path::new(&cli_manifest_file_path)
            .canonicalize()
            .unwrap();

        // make sure we're building/running the current version
        let mut kanidm = escargot::CargoBuild::new()
            .bin("kanidm")
            .current_release()
            .current_target()
            .manifest_path(&cli_manifest_file)
            .run()
            .unwrap();
        let mut kanidm = kanidm.command();
        kanidm.env("KANIDM_URL", &rsclient.get_url().to_string());
        kanidm.env("KANIDM_TOKEN_CACHE_PATH", &token_cache_path);
        kanidm
        }
    };

    code.into()
}