sagiegurari / cargo-make
1
use crate::logger;
2
use crate::logger::LoggerOptions;
3
use crate::types::{Config, ConfigSection, CrateInfo, EnvInfo, FlowInfo};
4
use ci_info;
5
use ci_info::types::CiInfo;
6
use fsio;
7
use git_info::types::GitInfo;
8
use indexmap::IndexMap;
9
use rust_info;
10
use rust_info::types::{RustChannel, RustInfo};
11
use rusty_hook as _;
12
use std::env;
13
use std::path::PathBuf;
14

15 8
pub(crate) fn on_test_startup() {
16 8
    logger::init(&LoggerOptions {
17 8
        level: "error".to_string(),
18
        color: true,
19 2
    });
20 8
}
21

22 8
pub(crate) fn is_linux() -> bool {
23 8
    on_test_startup();
24

25 2
    if cfg!(target_os = "linux") {
26 2
        true
27
    } else {
28 0
        false
29
    }
30 8
}
31

32 8
pub(crate) fn is_windows() -> bool {
33 8
    on_test_startup();
34

35 2
    if cfg!(windows) {
36 0
        true
37
    } else {
38 2
        false
39
    }
40 8
}
41

42 8
pub(crate) fn should_test(panic_if_false: bool) -> bool {
43 8
    on_test_startup();
44

45 8
    let rustinfo = rust_info::get();
46 8
    let rust_channel = rustinfo.channel.unwrap();
47

48 8
    if (is_linux() && rust_channel == RustChannel::Nightly) || !ci_info::is_ci() {
49 2
        true
50 6
    } else if panic_if_false {
51 6
        panic!("Skipped");
52
    } else {
53 6
        false
54
    }
55 8
}
56

57 8
pub(crate) fn get_os_runner() -> String {
58 8
    on_test_startup();
59

60 2
    if cfg!(windows) {
61 0
        "powershell.exe".to_string()
62
    } else {
63 8
        "sh".to_string()
64
    }
65 8
}
66

67 8
pub(crate) fn get_os_extension() -> String {
68 8
    on_test_startup();
69

70 2
    if cfg!(windows) {
71 0
        "ps1".to_string()
72
    } else {
73 8
        "sh".to_string()
74
    }
75 8
}
76

77 2
pub(crate) fn get_temp_test_directory() -> PathBuf {
78 2
    on_test_startup();
79

80 2
    let path = env::current_dir().unwrap();
81 2
    let directory = path.join("target/_cargo_make_temp/test");
82

83 2
    if directory.exists() {
84 2
        fsio::directory::delete(&directory).unwrap();
85
    }
86 2
    fsio::directory::create(&directory).unwrap();
87

88 0
    directory
89 2
}
90

91 8
pub(crate) fn is_not_rust_stable() -> bool {
92 8
    on_test_startup();
93

94 8
    let rustinfo = rust_info::get();
95 8
    let rust_channel = rustinfo.channel.unwrap();
96 6
    match rust_channel {
97 8
        RustChannel::Stable => false,
98 2
        RustChannel::Beta => true,
99 2
        RustChannel::Nightly => true,
100
    }
101 8
}
102

103 8
pub(crate) fn get_toolchain() -> String {
104 8
    on_test_startup();
105

106 8
    let rustinfo = rust_info::get();
107 8
    let rust_channel = rustinfo.channel.unwrap();
108 6
    let toolchain = match rust_channel {
109 8
        RustChannel::Stable => "stable",
110 2
        RustChannel::Beta => "beta",
111 2
        RustChannel::Nightly => "nightly",
112
    };
113

114 8
    toolchain.to_string()
115 8
}
116

117 8
pub(crate) fn create_empty_flow_info() -> FlowInfo {
118 8
    FlowInfo {
119 8
        config: Config {
120 8
            config: ConfigSection::new(),
121 8
            env_files: vec![],
122 8
            env: IndexMap::new(),
123 8
            env_scripts: vec![],
124 8
            tasks: IndexMap::new(),
125 0
        },
126 8
        task: "test".to_string(),
127 8
        env_info: EnvInfo {
128 8
            rust_info: RustInfo::new(),
129 8
            crate_info: CrateInfo::new(),
130 8
            git_info: GitInfo::new(),
131 8
            ci_info: CiInfo::new(),
132 0
        },
133
        disable_workspace: false,
134
        disable_on_error: false,
135
        allow_private: false,
136
        skip_init_end_tasks: false,
137 8
        cli_arguments: None,
138 0
    }
139 8
}

Read our documentation on viewing source code .

Loading