sagiegurari / cargo-make
1
use super::*;
2
use crate::test;
3
use crate::types::{InstallCrateInfo, InstallRustupComponentInfo, TestArg};
4
use envmnt;
5

6
#[test]
7 8
fn get_cargo_plugin_info_from_command_no_command() {
8 8
    let task = Task::new();
9

10 8
    let value = get_cargo_plugin_info_from_command(&task);
11

12 8
    assert!(value.is_none());
13 8
}
14

15
#[test]
16 8
fn get_cargo_plugin_info_from_command_not_cargo_command() {
17 8
    let mut task = Task::new();
18 8
    task.command = Some("echo".to_string());
19 8
    task.args = Some(vec!["test".to_string()]);
20

21 8
    let value = get_cargo_plugin_info_from_command(&task);
22

23 8
    assert!(value.is_none());
24 8
}
25

26
#[test]
27 8
fn get_cargo_plugin_info_from_command_no_args() {
28 8
    let mut task = Task::new();
29 8
    task.command = Some("cargo".to_string());
30 8
    task.args = None;
31

32 8
    let value = get_cargo_plugin_info_from_command(&task);
33

34 8
    assert!(value.is_none());
35 8
}
36

37
#[test]
38 8
fn get_cargo_plugin_info_from_command_empty_args() {
39 8
    let mut task = Task::new();
40 8
    task.command = Some("cargo".to_string());
41 8
    task.args = Some(vec![]);
42

43 8
    let value = get_cargo_plugin_info_from_command(&task);
44

45 8
    assert!(value.is_none());
46 8
}
47

48
#[test]
49 8
fn get_cargo_plugin_info_from_command_valid() {
50 8
    let mut task = Task::new();
51 8
    task.command = Some("cargo".to_string());
52 8
    task.args = Some(vec!["test".to_string()]);
53

54 8
    let value = get_cargo_plugin_info_from_command(&task);
55

56 8
    let (command, crate_name) = value.unwrap();
57

58 8
    assert_eq!(command, "test");
59 8
    assert_eq!(crate_name, "cargo-test");
60 8
}
61

62
#[test]
63 8
fn install_empty() {
64 8
    let task = Task::new();
65

66 8
    install(&task, &test::create_empty_flow_info());
67 8
}
68

69
#[test]
70 8
fn install_crate_already_installed() {
71 8
    let mut task = Task::new();
72 8
    task.install_crate = Some(InstallCrate::Value("test".to_string()));
73 8
    task.command = Some("cargo".to_string());
74 8
    task.args = Some(vec!["test".to_string()]);
75

76 8
    install(&task, &test::create_empty_flow_info());
77 8
}
78

79
#[test]
80
#[should_panic]
81 8
fn install_crate_missing_cargo_command() {
82 8
    let mut task = Task::new();
83 8
    task.install_crate = Some(InstallCrate::Value("test".to_string()));
84 8
    task.command = Some("cargo".to_string());
85

86 8
    install(&task, &test::create_empty_flow_info());
87 8
}
88

89
#[test]
90 8
fn install_crate_auto_detect_already_installed() {
91 8
    let mut task = Task::new();
92 8
    task.command = Some("cargo".to_string());
93 8
    task.args = Some(vec!["test".to_string()]);
94

95 8
    install(&task, &test::create_empty_flow_info());
96 8
}
97

98
#[test]
99
#[should_panic]
100 8
fn install_crate_auto_detect_unable_to_install() {
101 8
    let mut task = Task::new();
102 8
    task.command = Some("cargo".to_string());
103 8
    task.args = Some(vec!["badbadbad".to_string()]);
104

105 8
    install(&task, &test::create_empty_flow_info());
106 8
}
107

108
#[test]
109 8
fn install_rustup_via_crate_info() {
110 8
    let info = InstallCrateInfo {
111 8
        crate_name: "test".to_string(),
112 8
        binary: "cargo".to_string(),
113 8
        test_arg: TestArg {
114 8
            inner: vec!["--version".to_string()],
115
        },
116 8
        rustup_component_name: None,
117 8
        min_version: None,
118 0
    };
119

120 8
    let mut task = Task::new();
121 8
    task.command = Some("test".to_string());
122 8
    task.install_crate = Some(InstallCrate::CrateInfo(info));
123

124 8
    install(&task, &test::create_empty_flow_info());
125 8
}
126

127
#[test]
128 8
fn install_rustup_via_rustup_info() {
129 8
    let info = InstallRustupComponentInfo {
130 8
        rustup_component_name: "test".to_string(),
131 8
        binary: Some("cargo".to_string()),
132 8
        test_arg: Some(TestArg {
133 8
            inner: vec!["--version".to_string()],
134
        }),
135 0
    };
136

137 8
    let mut task = Task::new();
138 8
    task.command = Some("test".to_string());
139 8
    task.install_crate = Some(InstallCrate::RustupComponentInfo(info));
140

141 8
    install(&task, &test::create_empty_flow_info());
142 8
}
143

144
#[test]
145 8
fn install_script_ok() {
146 8
    let mut task = Task::new();
147 8
    task.install_script = Some(vec!["exit 0".to_string()]);
148

149 8
    install(&task, &test::create_empty_flow_info());
150 8
}
151

152
#[test]
153
#[should_panic]
154 8
fn install_script_error() {
155 8
    let mut task = Task::new();
156 8
    task.install_script = Some(vec!["exit 1".to_string()]);
157

158 8
    install(&task, &test::create_empty_flow_info());
159 8
}
160

161
#[test]
162 8
fn install_script_duckscript() {
163 8
    envmnt::remove("install_script_duckscript");
164 8
    assert!(!envmnt::exists("install_script_duckscript"));
165

166 8
    let mut task = Task::new();
167 8
    task.install_script = Some(vec![r#"#!@duckscript
168
    set_env install_script_duckscript true
169
    "#
170
    .to_string()]);
171

172 8
    install(&task, &test::create_empty_flow_info());
173

174 8
    assert!(envmnt::exists("install_script_duckscript"));
175 8
    assert!(envmnt::is_or("install_script_duckscript", false));
176 8
}
177

178
#[test]
179 8
fn install_script_error_ignore_errors() {
180 8
    let mut task = Task::new();
181 8
    task.ignore_errors = Some(true);
182 8
    task.install_script = Some(vec!["exit 1".to_string()]);
183

184 8
    install(&task, &test::create_empty_flow_info());
185 8
}

Read our documentation on viewing source code .

Loading