Something went wrong. Try again.
fork of Gleam compiler for Lua backend forked from gleam.run/gleam
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: 2023 The Gleam contributors
use crate::engine::Compilation;
use super::*;
#[test]fn compile_please() { let io = LanguageServerTestIO::new(); let mut engine = setup_engine(&io);
let response = engine.compile_please(); assert!(response.result.is_ok()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![]));
drop(engine); let actions = io.into_actions(); assert_eq!( actions, vec![ // new Action::DependencyDownloadingStarted, Action::DownloadDependencies, Action::DependencyDownloadingFinished, Action::LockBuild, Action::UnlockBuild, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, ] )}
#[test]fn compile_error_in_src() { let io = LanguageServerTestIO::new(); let mut engine = setup_engine(&io);
_ = io.src_module("app/error", "pub type Error {");
let response = engine.compile_please(); assert!(response.result.is_err()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![]));
drop(engine); let actions = io.into_actions(); assert_eq!( actions, vec![ // new Action::DependencyDownloadingStarted, Action::DownloadDependencies, Action::DependencyDownloadingFinished, Action::LockBuild, Action::UnlockBuild, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, ] )}
#[test]fn compile_error_in_test() { let io = LanguageServerTestIO::new(); let mut engine = setup_engine(&io);
_ = io.test_module("app/error", "pub type Error {");
let response = engine.compile_please(); assert!(response.result.is_err()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![]));
drop(engine); let actions = io.into_actions(); assert_eq!( actions, vec![ // new Action::DependencyDownloadingStarted, Action::DownloadDependencies, Action::DependencyDownloadingFinished, Action::LockBuild, Action::UnlockBuild, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, ] )}
#[test]fn compile_error_in_dev() { let io = LanguageServerTestIO::new(); let mut engine = setup_engine(&io);
_ = io.dev_module("app/error", "pub type Error {");
let response = engine.compile_please(); assert!(response.result.is_err()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![]));
drop(engine); let actions = io.into_actions(); assert_eq!( actions, vec![ // new Action::DependencyDownloadingStarted, Action::DownloadDependencies, Action::DependencyDownloadingFinished, Action::LockBuild, Action::UnlockBuild, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, ] )}
#[test]fn compile_recompile() { let io = LanguageServerTestIO::new(); let mut engine = setup_engine(&io);
let path = io.src_module("app", "pub fn main() { 0 }");
// The first time it compiles. let response = engine.compile_please(); assert!(response.result.is_ok()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![path.clone()]));
// The source file has been updated, so the file is compiled again. _ = io.src_module("app", "pub fn main() { 1 }"); let response = engine.compile_please(); assert!(response.result.is_ok()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![path]));
// This time it does not compile the module again, instead using the // cache from the previous run. let response = engine.compile_please(); assert_eq!(response.result, Ok(())); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![]));
drop(engine); let actions = io.into_actions(); assert_eq!( actions, vec![ // new Action::DependencyDownloadingStarted, Action::DownloadDependencies, Action::DependencyDownloadingFinished, Action::LockBuild, Action::UnlockBuild, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, ] )}
#[test]fn dep_compile_recompile() { let io = LanguageServerTestIO::new(); let mut engine = setup_engine(&io); add_path_dep(&mut engine, "mydep");
let path = io.path_dep_module("mydep", "moddy", "pub fn main() { 0 }");
// The first time it compiles. let response = engine.compile_please(); assert!(response.result.is_ok()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![path.clone()]));
assert!(!engine.compiler.project_compiler.packages.is_empty());
// The source file has been updated, so the file is compiled again. _ = io.path_dep_module("mydep", "moddy", "pub fn main() { 1 }"); let response = engine.compile_please(); assert!(response.result.is_ok()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![path]));
// This time it does not compile the module again, instead using the // cache from the previous run. let response = engine.compile_please(); assert!(response.result.is_ok()); assert!(response.warnings.is_empty()); assert_eq!(response.compilation, Compilation::Yes(vec![]));
drop(engine); let actions = io.into_actions(); assert_eq!( actions, vec![ // new Action::DependencyDownloadingStarted, Action::DownloadDependencies, Action::DependencyDownloadingFinished, Action::LockBuild, Action::UnlockBuild, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, // compile_please Action::CompilationStarted, Action::LockBuild, Action::UnlockBuild, Action::CompilationFinished, ] )}