Fix tests

pull/96/head
Chip Senkbeil 3 years ago
parent 788fa48e96
commit 4cb5ba3b98
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -416,7 +416,7 @@ mod tests {
"test-tenant",
req.id,
vec![ResponseData::Error(Error {
kind: ErrorKind::Other,
kind: ErrorKind::BrokenPipe,
description: String::from("some error"),
})],
))
@ -429,7 +429,7 @@ mod tests {
matches!(
&result,
Err(RemoteProcessError::TransportError(TransportError::IoError(x)))
if x.kind() == io::ErrorKind::InvalidData
if x.kind() == io::ErrorKind::BrokenPipe
),
"Unexpected result: {:?}",
result

@ -100,7 +100,7 @@ fn should_return_back_status_on_success(ctx: &'_ DistantServerCtx) {
// with / but thinks it's on windows and is providing \
#[rstest]
#[cfg_attr(windows, ignore)]
fn should_return_process_that_can_retrieve_stdout(ctx: &'_ DistantServerCtx) {
fn should_capture_all_stdout(ctx: &'_ DistantServerCtx) {
let lua = lua::make().unwrap();
let new_session = session::make_function(&lua, ctx).unwrap();
let schedule_fn = poll::make_function(&lua).unwrap();
@ -138,7 +138,7 @@ fn should_return_process_that_can_retrieve_stdout(ctx: &'_ DistantServerCtx) {
// with / but thinks it's on windows and is providing \
#[rstest]
#[cfg_attr(windows, ignore)]
fn should_return_process_that_can_retrieve_stderr(ctx: &'_ DistantServerCtx) {
fn should_capture_all_stderr(ctx: &'_ DistantServerCtx) {
let lua = lua::make().unwrap();
let new_session = session::make_function(&lua, ctx).unwrap();
let schedule_fn = poll::make_function(&lua).unwrap();

@ -10,6 +10,7 @@ mod read_file_text;
mod remove;
mod rename;
mod spawn;
mod spawn_wait;
mod system_info;
mod write_file;
mod write_file_text;

@ -0,0 +1,131 @@
use crate::common::{fixtures::*, lua, session};
use assert_fs::prelude::*;
use mlua::chunk;
use once_cell::sync::Lazy;
use rstest::*;
static TEMP_SCRIPT_DIR: Lazy<assert_fs::TempDir> = Lazy::new(|| assert_fs::TempDir::new().unwrap());
static SCRIPT_RUNNER: Lazy<String> = Lazy::new(|| String::from("bash"));
static ECHO_ARGS_TO_STDOUT_SH: Lazy<assert_fs::fixture::ChildPath> = Lazy::new(|| {
let script = TEMP_SCRIPT_DIR.child("echo_args_to_stdout.sh");
script
.write_str(indoc::indoc!(
r#"
#/usr/bin/env bash
printf "%s" "$*"
"#
))
.unwrap();
script
});
static ECHO_ARGS_TO_STDERR_SH: Lazy<assert_fs::fixture::ChildPath> = Lazy::new(|| {
let script = TEMP_SCRIPT_DIR.child("echo_args_to_stderr.sh");
script
.write_str(indoc::indoc!(
r#"
#/usr/bin/env bash
printf "%s" "$*" 1>&2
"#
))
.unwrap();
script
});
static DOES_NOT_EXIST_BIN: Lazy<assert_fs::fixture::ChildPath> =
Lazy::new(|| TEMP_SCRIPT_DIR.child("does_not_exist_bin"));
#[rstest]
fn should_return_error_on_failure(ctx: &'_ DistantServerCtx) {
let lua = lua::make().unwrap();
let new_session = session::make_function(&lua, ctx).unwrap();
let cmd = DOES_NOT_EXIST_BIN.to_str().unwrap().to_string();
let args: Vec<String> = Vec::new();
let result = lua
.load(chunk! {
local session = $new_session()
local status, _ = pcall(session.spawn_wait, session, {
cmd = $cmd,
args = $args
})
assert(not status, "Unexpectedly succeeded!")
})
.exec();
assert!(result.is_ok(), "Failed: {}", result.unwrap_err());
}
#[rstest]
fn should_return_back_process_on_success(ctx: &'_ DistantServerCtx) {
let lua = lua::make().unwrap();
let new_session = session::make_function(&lua, ctx).unwrap();
let cmd = SCRIPT_RUNNER.to_string();
let args = vec![ECHO_ARGS_TO_STDOUT_SH.to_str().unwrap().to_string()];
let result = lua
.load(chunk! {
local session = $new_session()
local output = session:spawn_wait({ cmd = $cmd, args = $args })
assert(output, "Missing process output")
assert(output.success, "Process unexpectedly failed")
})
.exec();
assert!(result.is_ok(), "Failed: {}", result.unwrap_err());
}
// NOTE: Ignoring on windows because it's using WSL which wants a Linux path
// with / but thinks it's on windows and is providing \
#[rstest]
#[cfg_attr(windows, ignore)]
fn should_capture_all_stdout(ctx: &'_ DistantServerCtx) {
let lua = lua::make().unwrap();
let new_session = session::make_function(&lua, ctx).unwrap();
let cmd = SCRIPT_RUNNER.to_string();
let args = vec![
ECHO_ARGS_TO_STDOUT_SH.to_str().unwrap().to_string(),
String::from("some stdout"),
];
let result = lua
.load(chunk! {
local session = $new_session()
local output = session:spawn_wait({ cmd = $cmd, args = $args })
assert(output, "Missing process output")
assert(output.success, "Process unexpectedly failed")
assert(output.stdout == "some stdout", "Unexpected stdout: " .. output.stdout)
assert(output.stderr == "", "Unexpected stderr: " .. output.stderr)
})
.exec();
assert!(result.is_ok(), "Failed: {}", result.unwrap_err());
}
// NOTE: Ignoring on windows because it's using WSL which wants a Linux path
// with / but thinks it's on windows and is providing \
#[rstest]
#[cfg_attr(windows, ignore)]
fn should_capture_all_stderr(ctx: &'_ DistantServerCtx) {
let lua = lua::make().unwrap();
let new_session = session::make_function(&lua, ctx).unwrap();
let cmd = SCRIPT_RUNNER.to_string();
let args = vec![
ECHO_ARGS_TO_STDERR_SH.to_str().unwrap().to_string(),
String::from("some stderr"),
];
let result = lua
.load(chunk! {
local session = $new_session()
local output = session:spawn_wait({ cmd = $cmd, args = $args })
assert(output, "Missing process output")
assert(output.success, "Process unexpectedly failed")
assert(output.stdout == "", "Unexpected stdout: " .. output.stdout)
assert(output.stderr == "some stderr", "Unexpected stderr: " .. output.stderr)
})
.exec();
assert!(result.is_ok(), "Failed: {}", result.unwrap_err());
}

@ -323,7 +323,7 @@ impl UserData for Session {
Ok(RemoteLspProcess::from_distant(proc))
});
impl_methods!(methods, system_info, |lua, info| {
Ok(lua.to_value(&info)?)
lua.to_value(&info)
});
impl_methods!(methods, write_file);
impl_methods!(methods, write_file_text);

@ -174,7 +174,7 @@ make_api!(
{ cmd: String, args: Vec<String> },
|channel, tenant, params| {
let proc = channel.spawn(tenant, params.cmd, params.args).await.to_lua_err()?;
let id = LuaRemoteProcess::from_distant(proc)?.id;
let id = LuaRemoteProcess::from_distant_async(proc).await?.id;
LuaRemoteProcess::output_async(id).await
}
);

@ -58,8 +58,12 @@ macro_rules! impl_process {
}
pub fn from_distant(proc: $type) -> LuaResult<Self> {
runtime::get_runtime()?.block_on(Self::from_distant_async(proc))
}
pub async fn from_distant_async(proc: $type) -> LuaResult<Self> {
let id = proc.id();
runtime::get_runtime()?.block_on($map_name.write()).insert(id, proc);
$map_name.write().await.insert(id, proc);
Ok(Self::new(id))
}

@ -158,7 +158,7 @@ fn yield_an_error_when_fails(mut action_cmd: Command) {
.args(&["proc-run", "--"])
.arg(DOES_NOT_EXIST_BIN.to_str().unwrap())
.assert()
.code(ExitCode::DataErr.to_i32())
.code(ExitCode::IoError.to_i32())
.stdout("")
.stderr("");
}

Loading…
Cancel
Save