clap/clap_generate/tests/completions/mod.rs
Arne Beer 84d99d6bb8 Give each shell test their own App
Right now, adjusting test cases to cover some special edge-cases for a
specific shell is a little problematic.

For instance, if you add a special character that needs escaping
to one of the help strings, not only the tests for the shell you're
currently working on need adjustments, but rather all shell tests!

Contributors can often only work on one specific shell. The
need to adjust shells they don't know anything about discourages
testing or makes it simply impossible for a single contributor.

Arguably, this commit introduces a lot of code duplication, but on
the other hand it also makes testing a lot easier.
2020-12-28 01:40:15 +01:00

32 lines
739 B
Rust

use clap::{App, Arg, ValueHint};
use clap_generate::{generate, generators::*};
use std::fmt;
mod bash;
mod elvish;
mod fish;
mod powershell;
mod zsh;
#[derive(PartialEq, Eq)]
pub struct PrettyString<'a>(pub &'a str);
impl<'a> fmt::Debug for PrettyString<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.0)
}
}
macro_rules! assert_eq {
($left:expr, $right:expr) => {
pretty_assertions::assert_eq!(PrettyString($left), PrettyString($right));
};
}
pub fn common<G: Generator>(app: &mut App, name: &str, fixture: &str) {
let mut buf = vec![];
generate::<G, _>(app, name, &mut buf);
let string = String::from_utf8(buf).unwrap();
assert_eq!(&string, fixture);
}