Skip to content

Commit

Permalink
test: Fixup doctest and run them in load crate
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp committed Dec 30, 2019
1 parent 7c83027 commit ae53ca3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 21 deletions.
3 changes: 0 additions & 3 deletions load/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.8.1-development"
authors = ["Brian Pearce"]
publish = false

[lib]
doctest = false

[dependencies]
common = { path = "../common" }
dirs = "2.0.2"
Expand Down
44 changes: 39 additions & 5 deletions load/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,35 @@ static TMUX_ENV_VAR: &str = "TMUX";
/// Read in the contents of the config (which should be Yaml), and parse the
/// contents as yaml.
///
/// `project_name`: The name of the project, corresponding to the project config
/// file.
/// `project_paths`: The struct of paths
///
/// # Examples
///
/// Given the project name "compiler" and a project file found at:
/// `~/.muxed/compiler.yml`.
///
/// ```
/// let yaml: Result<Vec<Yaml>, String> = read("compiler".to_string());
/// ```
/// ```rust,no_run
/// extern crate common;
/// extern crate load;
/// extern crate yaml_rust;
///
/// `project_name`: The name of the project, corresponding to the project config
/// file.
/// use common::project_paths::ProjectPaths;
/// use load::project::read;
/// use std::path::PathBuf;
/// use yaml_rust::{Yaml, YamlLoader};
///
/// let paths = ProjectPaths::new(
/// PathBuf::from("/tmp"),
/// PathBuf::from("/tmp/.muxed"),
/// PathBuf::from("/tmp/.muxed/projectname.yml")
/// );
///
/// let yaml: Result<Vec<Yaml>, String> = read("compiler", &paths);
///
/// assert!(yaml.is_ok());
/// ```
pub fn read(project_name: &str, project_paths: &ProjectPaths) -> Result<Vec<Yaml>, String> {
check_first_run(&project_paths.project_directory)?;

Expand Down Expand Up @@ -57,6 +75,22 @@ pub fn session_exists(project_name: &str) -> Option<Commands> {

/// Check to see how we want to open the project. Do we need to attach to a new
/// tmux session or can we switch the client from a running session.
///
/// # Examples
///
/// ```rust
/// extern crate load;
///
/// use load::command::{Attach, Commands, Command};
/// use load::project::open;
///
/// let correct_type = match open("muxed") {
/// Commands::Attach(_) => true,
/// _ => false,
/// };
///
/// assert!(correct_type)
/// ```
pub fn open(project_name: &str) -> Commands {
if env::var_os(TMUX_ENV_VAR).is_some() {
SwitchClient::new(&project_name).into()
Expand Down
39 changes: 26 additions & 13 deletions load/src/tmux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ static TMUX_NAME: &str = "tmux";
///
/// # Examples
///
/// ```
/// let _ = call(&["new-window", "-t", "muxed", "-c", "~/Projects/muxed/"]);
/// ```rust
/// extern crate load;
/// use load::tmux::call;
///
/// let _ = call(&["new-window", "-t", "muxed-test", "-c", "~/Projects/muxed/"]);
/// let _ = call(&["kill-session", "-t", "muxed-test"]);
/// ```
pub fn call(args: &[&str]) -> Result<Output, io::Error> {
//println!("{:?}", &args);
Expand All @@ -35,14 +39,18 @@ pub fn call(args: &[&str]) -> Result<Output, io::Error> {

/// Has session is used firgure out if a named session is already running.
///
/// `target`: A string represented by the `{named_session}`
///
/// # Examples
///
/// ```
/// tmux::has_session("muxed".to_string());
/// => ExitStatus
/// ```
/// ```rust
/// extern crate load;
/// use load::tmux;
///
/// `target`: A string represented by the `{named_session}`
/// let session = tmux::has_session("muxed");
///
/// assert!(!session.success());
/// ```
pub fn has_session(target: &str) -> ExitStatus {
let output =
call(&["has-session", "-t", target]).expect("failed to see if the session existed");
Expand All @@ -53,9 +61,11 @@ pub fn has_session(target: &str) -> ExitStatus {
///
/// # Examples
///
/// ```
/// ```rust
/// extern crate load;
/// use load::tmux;
///
/// tmux::get_config();
/// => "some-option false\npane-base-index 0"
/// ```
pub fn get_config() -> String {
let output = call(&["start-server", ";", "show-options", "-g", ";", "show-options", "-g", "-w"])
Expand All @@ -69,11 +79,14 @@ pub fn get_config() -> String {
///
/// # Examples
///
/// ```
/// let session_name = "muxed".to_string();
/// tmux::attach(muxed);
/// ```
/// `session_name: The active tmux session name.
///
/// ```rust,no_run
/// extern crate load;
/// use load::tmux;
///
/// tmux::attach(&["muxed"]);
/// ```
pub fn attach(args: &[&str]) -> Result<Output, io::Error> {
let arg_string = [&[TMUX_NAME], &args[..]].concat().join(" ");
let system_call = CString::new(arg_string).unwrap();
Expand Down

0 comments on commit ae53ca3

Please sign in to comment.