⭐️ A friendly language for building type-safe, scalable systems!
1use crate::language_server::engine::Compilation;
2
3use super::*;
4
5#[test]
6fn compile_please() {
7 let io = LanguageServerTestIO::new();
8 let mut engine = setup_engine(&io);
9
10 let response = engine.compile_please();
11 assert!(response.result.is_ok());
12 assert!(response.warnings.is_empty());
13 assert_eq!(response.compilation, Compilation::Yes(vec![]));
14
15 drop(engine);
16 let actions = io.into_actions();
17 assert_eq!(
18 actions,
19 vec![
20 // new
21 Action::DependencyDownloadingStarted,
22 Action::DownloadDependencies,
23 Action::DependencyDownloadingFinished,
24 Action::LockBuild,
25 Action::UnlockBuild,
26 // compile_please
27 Action::CompilationStarted,
28 Action::LockBuild,
29 Action::UnlockBuild,
30 Action::CompilationFinished,
31 ]
32 )
33}
34
35#[test]
36fn compile_error_in_src() {
37 let io = LanguageServerTestIO::new();
38 let mut engine = setup_engine(&io);
39
40 _ = io.src_module("app/error", "pub type Error {");
41
42 let response = engine.compile_please();
43 assert!(response.result.is_err());
44 assert!(response.warnings.is_empty());
45 assert_eq!(response.compilation, Compilation::Yes(vec![]));
46
47 drop(engine);
48 let actions = io.into_actions();
49 assert_eq!(
50 actions,
51 vec![
52 // new
53 Action::DependencyDownloadingStarted,
54 Action::DownloadDependencies,
55 Action::DependencyDownloadingFinished,
56 Action::LockBuild,
57 Action::UnlockBuild,
58 // compile_please
59 Action::CompilationStarted,
60 Action::LockBuild,
61 Action::UnlockBuild,
62 Action::CompilationFinished,
63 ]
64 )
65}
66
67#[test]
68fn compile_error_in_test() {
69 let io = LanguageServerTestIO::new();
70 let mut engine = setup_engine(&io);
71
72 _ = io.test_module("app/error", "pub type Error {");
73
74 let response = engine.compile_please();
75 assert!(response.result.is_err());
76 assert!(response.warnings.is_empty());
77 assert_eq!(response.compilation, Compilation::Yes(vec![]));
78
79 drop(engine);
80 let actions = io.into_actions();
81 assert_eq!(
82 actions,
83 vec![
84 // new
85 Action::DependencyDownloadingStarted,
86 Action::DownloadDependencies,
87 Action::DependencyDownloadingFinished,
88 Action::LockBuild,
89 Action::UnlockBuild,
90 // compile_please
91 Action::CompilationStarted,
92 Action::LockBuild,
93 Action::UnlockBuild,
94 Action::CompilationFinished,
95 ]
96 )
97}
98
99#[test]
100fn compile_error_in_dev() {
101 let io = LanguageServerTestIO::new();
102 let mut engine = setup_engine(&io);
103
104 _ = io.dev_module("app/error", "pub type Error {");
105
106 let response = engine.compile_please();
107 assert!(response.result.is_err());
108 assert!(response.warnings.is_empty());
109 assert_eq!(response.compilation, Compilation::Yes(vec![]));
110
111 drop(engine);
112 let actions = io.into_actions();
113 assert_eq!(
114 actions,
115 vec![
116 // new
117 Action::DependencyDownloadingStarted,
118 Action::DownloadDependencies,
119 Action::DependencyDownloadingFinished,
120 Action::LockBuild,
121 Action::UnlockBuild,
122 // compile_please
123 Action::CompilationStarted,
124 Action::LockBuild,
125 Action::UnlockBuild,
126 Action::CompilationFinished,
127 ]
128 )
129}
130
131#[test]
132fn compile_recompile() {
133 let io = LanguageServerTestIO::new();
134 let mut engine = setup_engine(&io);
135
136 let path = io.src_module("app", "pub fn main() { 0 }");
137
138 // The first time it compiles.
139 let response = engine.compile_please();
140 assert!(response.result.is_ok());
141 assert!(response.warnings.is_empty());
142 assert_eq!(response.compilation, Compilation::Yes(vec![path.clone()]));
143
144 // The source file has been updated, so the file is compiled again.
145 _ = io.src_module("app", "pub fn main() { 1 }");
146 let response = engine.compile_please();
147 assert!(response.result.is_ok());
148 assert!(response.warnings.is_empty());
149 assert_eq!(response.compilation, Compilation::Yes(vec![path]));
150
151 // This time it does not compile the module again, instead using the
152 // cache from the previous run.
153 let response = engine.compile_please();
154 assert_eq!(response.result, Ok(()));
155 assert!(response.warnings.is_empty());
156 assert_eq!(response.compilation, Compilation::Yes(vec![]));
157
158 drop(engine);
159 let actions = io.into_actions();
160 assert_eq!(
161 actions,
162 vec![
163 // new
164 Action::DependencyDownloadingStarted,
165 Action::DownloadDependencies,
166 Action::DependencyDownloadingFinished,
167 Action::LockBuild,
168 Action::UnlockBuild,
169 // compile_please
170 Action::CompilationStarted,
171 Action::LockBuild,
172 Action::UnlockBuild,
173 Action::CompilationFinished,
174 // compile_please
175 Action::CompilationStarted,
176 Action::LockBuild,
177 Action::UnlockBuild,
178 Action::CompilationFinished,
179 // compile_please
180 Action::CompilationStarted,
181 Action::LockBuild,
182 Action::UnlockBuild,
183 Action::CompilationFinished,
184 ]
185 )
186}
187
188#[test]
189fn dep_compile_recompile() {
190 let io = LanguageServerTestIO::new();
191 let mut engine = setup_engine(&io);
192 add_path_dep(&mut engine, "mydep");
193
194 let path = io.path_dep_module("mydep", "moddy", "pub fn main() { 0 }");
195
196 // The first time it compiles.
197 let response = engine.compile_please();
198 assert!(response.result.is_ok());
199 assert!(response.warnings.is_empty());
200 assert_eq!(response.compilation, Compilation::Yes(vec![path.clone()]));
201
202 assert!(!engine.compiler.project_compiler.packages.is_empty());
203
204 // The source file has been updated, so the file is compiled again.
205 _ = io.path_dep_module("mydep", "moddy", "pub fn main() { 1 }");
206 let response = engine.compile_please();
207 assert!(response.result.is_ok());
208 assert!(response.warnings.is_empty());
209 assert_eq!(response.compilation, Compilation::Yes(vec![path]));
210
211 // This time it does not compile the module again, instead using the
212 // cache from the previous run.
213 let response = engine.compile_please();
214 assert!(response.result.is_ok());
215 assert!(response.warnings.is_empty());
216 assert_eq!(response.compilation, Compilation::Yes(vec![]));
217
218 drop(engine);
219 let actions = io.into_actions();
220 assert_eq!(
221 actions,
222 vec![
223 // new
224 Action::DependencyDownloadingStarted,
225 Action::DownloadDependencies,
226 Action::DependencyDownloadingFinished,
227 Action::LockBuild,
228 Action::UnlockBuild,
229 // compile_please
230 Action::CompilationStarted,
231 Action::LockBuild,
232 Action::UnlockBuild,
233 Action::CompilationFinished,
234 // compile_please
235 Action::CompilationStarted,
236 Action::LockBuild,
237 Action::UnlockBuild,
238 Action::CompilationFinished,
239 // compile_please
240 Action::CompilationStarted,
241 Action::LockBuild,
242 Action::UnlockBuild,
243 Action::CompilationFinished,
244 ]
245 )
246}