Skip to content

Commit

Permalink
📃 docs: Add some rustdoc, with minor tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
wychlw committed Oct 21, 2024
1 parent c854ba1 commit 9f3e429
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 210 deletions.
1 change: 1 addition & 0 deletions src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl Shell {
let stop: std::sync::MutexGuard<'_, bool> = stop.lock().unwrap();
if *stop {
log!("Stop shell process");
break;
}
}
let mut buf = Vec::new();
Expand Down
12 changes: 10 additions & 2 deletions src/exec/cli_api.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
//! The API for the CLI test.
use std::error::Error;

use crate::cli::tty::WrapperTty;

/// The API for the CLI test.
pub trait CliTestApi: WrapperTty {
///
/// Run a script in the terminal, wait for the script to finish(or timeout), and return the output.
///
/// You may found this func includes assert_script_run and script_output
fn script_run(&mut self, script: &str, timeout: u32) -> Result<String, Box<dyn Error>>;

/// Run a script in the terminal which is a background command
fn background_script_run(&mut self, script: &str) -> Result<(), Box<dyn Error>>;

/// Write someting to the terminal.
fn writeln(&mut self, script: &str) -> Result<(), Box<dyn Error>>;

/// Wait for the terminal to output the expected string. Output the terminal output when the expected string is found.
fn wait_serial(&mut self, expected: &str, timeout: u32) -> Result<String, Box<dyn Error>>;
}

pub trait SudoCliTestApi: CliTestApi {
///
/// Just like script_run, but with sudo.
///
/// You may found this func includes assert_script_sudo and script_output
fn script_sudo(&mut self, script: &str, timeout: u32) -> Result<String, Box<dyn Error>>;
Expand Down
4 changes: 3 additions & 1 deletion src/exec/cli_exec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The implementation of the CLI tester. Look at [`CliTestApi`] for more information.
use std::{
error::Error,
thread::sleep,
Expand Down Expand Up @@ -167,7 +169,7 @@ impl CliTestApi for CliTester {
}
fn script_run(&mut self, script: &str, timeout: u32) -> Result<String, Box<dyn Error>> {
let mut cmd = script.to_owned();
let echo_content_rand = String::from_utf8(rand_string(8)).unwrap();
let echo_content_rand = rand_string(8);

cmd += " && echo ";
cmd += &echo_content_rand;
Expand Down
2 changes: 1 addition & 1 deletion src/exec/gui_exec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Executor gor GUI
//! Executor for GUI. Look at [`GuiTestApi`] for more details.
//!
use std::{error::Error, time::Instant};
Expand Down
7 changes: 7 additions & 0 deletions src/exec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//! How to execute some operations for the CLI and GUI.
//!
//! This part contains the interactive API for the CLI and GUI. You definitely
//! could use the CLI API and GUI API directly, but you really want to see a bunch of
//! blocking IO and u8 slices?
//! So these wrappers are here to provide high-level API for the CLI and GUI.
pub mod cli_api;
pub mod cli_exec;
pub mod gui_api;
Expand Down
6 changes: 5 additions & 1 deletion src/pythonapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod util;

pub mod sdwirec;

pub mod pylogger;
mod pylogger;
pub mod asciicast;

pub mod deansi;
Expand All @@ -29,6 +29,8 @@ use tee::Tee;
use shell_like::PyTty;
use util::{get_log_level, run_ui, set_log_level};

use crate::ui::register_ui;

#[pymodule]
#[pyo3(name = "tester")]
fn tester(m: &Bound<'_, PyModule>) -> PyResult<()> {
Expand All @@ -52,5 +54,7 @@ fn tester(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(warn, m)?)?;
m.add_function(wrap_pyfunction!(err, m)?)?;

register_ui(m)?;

Ok(())
}
203 changes: 0 additions & 203 deletions src/ui/cli_hooker.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/util/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub enum LogLevel {
Error = 30,
}

static mut LOG_LEVEL: i32 = LogLevel::Info as i32;
static mut LOG_LEVEL: i32 = LogLevel::Debug as i32;

fn __get_log_level() -> i32 {
unsafe { LOG_LEVEL }
Expand Down
7 changes: 6 additions & 1 deletion src/util/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ macro_rules! unfinished {
};
}

pub fn rand_string(len: usize) -> Vec<u8> {
pub fn rand_u8(len: usize) -> Vec<u8> {
thread_rng()
.sample_iter(&Alphanumeric)
.take(len)
.collect::<Vec<u8>>()
}


pub fn rand_string(len: usize) -> String {
String::from_utf8(rand_u8(len)).unwrap()
}

pub fn try_read<R: BufRead + ?Sized>(
r: &mut R,
buf: &mut Vec<u8>,
Expand Down

0 comments on commit 9f3e429

Please sign in to comment.