Make CLI tests less flaky

This commit is contained in:
Filip Tibell 2023-01-24 13:48:37 -05:00
parent ef61531199
commit 5c6fdb4a6e
No known key found for this signature in database
2 changed files with 23 additions and 14 deletions

View file

@ -2,7 +2,6 @@ use std::{fs::read_to_string, process::ExitCode};
use anyhow::Result; use anyhow::Result;
use clap::{CommandFactory, Parser}; use clap::{CommandFactory, Parser};
use mlua::prelude::*;
use lune::Lune; use lune::Lune;
@ -75,23 +74,18 @@ impl Cli {
let download_types_requested = self.download_selene_types || self.download_luau_types; let download_types_requested = self.download_selene_types || self.download_luau_types;
if download_types_requested { if download_types_requested {
let client = GithubClient::new(); let client = GithubClient::new();
let release = client let release = client.fetch_release_for_this_version().await?;
.fetch_release_for_this_version()
.await
.map_err(LuaError::external)?;
if self.download_selene_types { if self.download_selene_types {
println!("Downloading Selene type definitions..."); println!("Downloading Selene type definitions...");
client client
.fetch_release_asset(&release, LUNE_SELENE_FILE_NAME) .fetch_release_asset(&release, LUNE_SELENE_FILE_NAME)
.await .await?;
.map_err(LuaError::external)?;
} }
if self.download_luau_types { if self.download_luau_types {
println!("Downloading Luau type definitions..."); println!("Downloading Luau type definitions...");
client client
.fetch_release_asset(&release, LUNE_LUAU_FILE_NAME) .fetch_release_asset(&release, LUNE_LUAU_FILE_NAME)
.await .await?;
.map_err(LuaError::external)?;
} }
} }
if self.script_path.is_none() { if self.script_path.is_none() {
@ -127,16 +121,29 @@ impl Cli {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{Cli, LUNE_LUAU_FILE_NAME, LUNE_SELENE_FILE_NAME}; use std::{env::set_current_dir, time::Duration};
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use serde_json::Value; use serde_json::Value;
use smol::fs::{create_dir_all, read_to_string}; use smol::{
use std::env::set_current_dir; fs::{create_dir_all, read_to_string},
Timer,
};
use super::{Cli, LUNE_LUAU_FILE_NAME, LUNE_SELENE_FILE_NAME};
async fn sleep(seconds: f32) -> Result<()> {
Timer::after(Duration::from_secs_f32(seconds)).await;
Ok(())
}
async fn run_cli(cli: Cli) -> Result<()> { async fn run_cli(cli: Cli) -> Result<()> {
create_dir_all("bin").await?; create_dir_all("bin").await?;
sleep(0.125).await?;
set_current_dir("bin")?; set_current_dir("bin")?;
sleep(0.125).await?;
cli.run().await?; cli.run().await?;
sleep(0.125).await?;
Ok(()) Ok(())
} }

View file

@ -187,10 +187,12 @@ impl Lune {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::Lune; use std::process::ExitCode;
use anyhow::Result; use anyhow::Result;
use smol::fs::read_to_string; use smol::fs::read_to_string;
use std::process::ExitCode;
use crate::Lune;
const ARGS: &[&str] = &["Foo", "Bar"]; const ARGS: &[&str] = &["Foo", "Bar"];