1
use clap::Parser;
2
use color_eyre::Result;
3
use tempfile::tempdir;
4
use zork::cli::input::CliArgs;
5

            
6
#[test]
7
2
fn test_clang_full_process() -> Result<()> {
8
1
    let project_name = "clang_example";
9

            
10
1
    let tempdir = tempdir()?;
11
1
    let path = tempdir.path();
12
1
    let binding = path.join(project_name);
13
1
    let project_root = binding.to_string_lossy();
14

            
15
1
    let new_project_cretion_result = zork::worker::run_zork(&CliArgs::parse_from([
16
        "",
17
        "--root",
18
1
        path.to_str().unwrap(),
19
        "new",
20
        project_name,
21
        "--compiler",
22
        "clang",
23
        "--template",
24
        "basic",
25
1
    ]));
26

            
27
    assert!(
28
1
        new_project_cretion_result.is_ok(),
29
        "{}",
30
        new_project_cretion_result.unwrap_err()
31
    );
32

            
33
1
    let process_result = zork::worker::run_zork(&CliArgs::parse_from([
34
        "",
35
        "-vv",
36
        "--root",
37
1
        &project_root,
38
        /* "--driver-path",
39
        "clang++-16", // Local cfg issues */
40
        "run",
41
1
    ]));
42
1
    assert!(process_result.is_ok(), "{}", process_result.unwrap_err());
43

            
44
1
    Ok(tempdir.close()?)
45
2
}
46

            
47
#[cfg(target_os = "windows")]
48
#[test]
49
fn test_msvc_process_basic_template() -> Result<()> {
50
    let project_name = "msvc_example_basic";
51

            
52
    let tempdir = tempdir()?;
53
    let path = tempdir.path();
54
    let binding = path.join(project_name);
55
    let project_root = binding.to_string_lossy();
56

            
57
    assert!(zork::worker::run_zork(&CliArgs::parse_from([
58
        "",
59
        "--root",
60
        path.to_str().unwrap(),
61
        "new",
62
        project_name,
63
        "--compiler",
64
        "msvc",
65
        "--template",
66
        "basic"
67
    ]))
68
    .is_ok());
69

            
70
    assert!(zork::worker::run_zork(&CliArgs::parse_from([
71
        "",
72
        "-vv",
73
        "--root",
74
        &project_root,
75
        "run"
76
    ]))
77
    .is_ok());
78

            
79
    Ok(tempdir.close()?)
80
}
81

            
82
#[cfg(target_os = "windows")]
83
#[test]
84
fn test_msvc_full_process() -> Result<()> {
85
    let project_name = "msvc_example";
86

            
87
    let tempdir = tempdir()?;
88
    let path = tempdir.path();
89
    let binding = path.join(project_name);
90
    let project_root = binding.to_string_lossy();
91

            
92
    assert!(zork::worker::run_zork(&CliArgs::parse_from([
93
        "",
94
        "--root",
95
        path.to_str().unwrap(),
96
        "new",
97
        project_name,
98
        "--compiler",
99
        "msvc"
100
    ]))
101
    .is_ok());
102

            
103
    assert!(zork::worker::run_zork(&CliArgs::parse_from([
104
        "",
105
        "-vv",
106
        "--root",
107
        &project_root,
108
        "run"
109
    ]))
110
    .is_ok());
111

            
112
    Ok(tempdir.close()?)
113
}
114

            
115
#[cfg(target_os = "windows")]
116
#[test]
117
fn test_gcc_windows_full_process() -> Result<()> {
118
    let project_name = "gcc_example";
119

            
120
    let tempdir = tempdir()?;
121
    let path = tempdir.path();
122
    let binding = path.join(project_name);
123
    let project_root = binding.to_string_lossy();
124

            
125
    assert!(zork::worker::run_zork(&CliArgs::parse_from([
126
        "",
127
        "--root",
128
        path.to_str().unwrap(),
129
        "new",
130
        project_name,
131
        "--compiler",
132
        "gcc"
133
    ]))
134
    .is_ok());
135

            
136
    assert!(zork::worker::run_zork(&CliArgs::parse_from([
137
        "",
138
        "-vv",
139
        "--root",
140
        &project_root,
141
        "run"
142
    ]))
143
    .is_ok());
144

            
145
    Ok(tempdir.close()?)
146
}
147

            
148
#[cfg(target_os = "linux")]
149
#[test]
150
/*
151
In the GitHub's virtual machines, we are still unable, due
152
to the gcm.cache path.
153

            
154
cc1plus: fatal error: iostream: No such file or directory
155
compilation terminated.
156
In module imported at /tmp/.tmpGaFLnR/gcc_example/main.cpp:8:5:
157
/usr/include/c++/13.2.1/iostream: error: failed to read compiled module: No such file or directory
158
/usr/include/c++/13.2.1/iostream: note: compiled module file is ‘gcm.cache/./usr/include/c++/13.2.1/iostream.gcm’
159
/usr/include/c++/13.2.1/iostream: note: imports must be built before being imported
160
/usr/include/c++/13.2.1/iostream: fatal error: returning to the gate for a mechanical issue
161
compilation terminated.
162
 */
163
2
fn test_gcc_full_process() -> Result<()> {
164
    use std::fs;
165

            
166
1
    let project_name = "gcc_example";
167

            
168
1
    let tempdir = tempdir()?;
169
1
    let path = tempdir.path();
170
1
    let binding = path.join(project_name);
171
1
    let project_root = binding.to_string_lossy();
172

            
173
1
    let new_project_cretion_result = zork::worker::run_zork(&CliArgs::parse_from([
174
        "",
175
        "--root",
176
1
        path.to_str().unwrap(),
177
        "new",
178
        project_name,
179
        "--compiler",
180
        "gcc",
181
        "--template",
182
        "basic",
183
1
    ]));
184

            
185
    assert!(
186
1
        new_project_cretion_result.is_ok(),
187
        "{}",
188
        new_project_cretion_result.unwrap_err()
189
    );
190

            
191
1
    let process_result = zork::worker::run_zork(&CliArgs::parse_from([
192
        "",
193
        "-vv",
194
        "--root",
195
1
        &project_root,
196
        "run",
197
1
    ]));
198
1
    assert!(process_result.is_ok(), "{}", process_result.unwrap_err());
199

            
200
    // Clearing the GCC modules cache (weird, isn't generated at the invoked project's root)
201
    // maybe we should change dir? but that collide with the purpose of specifiying the project
202
    // root clearly
203
1
    fs::remove_dir_all("./gcm.cache")?;
204

            
205
1
    Ok(tempdir.close()?)
206
2
}
207

            
208
mod local_env_tests {
209
    use super::*;
210
    use std::env;
211

            
212
    /// This test allows the developers to specify a path in local environments, having the opportunity
213
    /// to debug the Zork++ source code from a concrete location.
214
    ///
215
    /// For example, we can use the `[Zero project source code](https://github.com/zerodaycode/Zero)`
216
    /// in our local machines to debug the changes that we are making to Zork++ in real time,
217
    /// so by specifying a path, we allow Zork++ to start it's job in another concrete location,
218
    /// as if the binary where called from the specified path, and by running this test we can
219
    /// use a debugger to figure out what our changes are doing and how are affecting the codebase.
220
    #[test]
221
    #[ignore]
222
    fn test_local_clang_full_process_manually_by_specifying_the_project_root() {
223
        // Using env::home_dir because this test should be Unix specific
224
        // For any developer, change the path to whatever C++ project based on modules
225
        // you want to test Zork++ against
226
        #[allow(deprecated)]
227
        let mut path = env::home_dir().unwrap();
228
        path.push("code");
229
        path.push("c++");
230
        path.push("Zero");
231

            
232
        let process = zork::worker::run_zork(&CliArgs::parse_from([
233
            "",
234
            "-vv",
235
            "-c",
236
            "--root",
237
            &path.display().to_string(),
238
            "--driver-path",
239
            "clang++-16",
240
            "--match-files",
241
            "local_linux",
242
            "run",
243
        ]));
244
        assert!(process.is_ok());
245
    }
246
}