Allow macro trailing comma (#314)

This commit is contained in:
Cedric Hutchings 2019-11-14 01:17:10 -05:00 committed by Timon
parent 268230c579
commit 9fdc6318b2
2 changed files with 42 additions and 2 deletions

View File

@ -1,3 +1,7 @@
# Version Master
- `queue!` & `execute!` macros allow trailing comma
# Version 0.13.3
- Remove thread from AsyncReader on Windows.

View File

@ -70,7 +70,7 @@ macro_rules! write_cout {
/// - Queuing might sound that there is some scheduling going on, however, this means that we write to the stdout without flushing which will cause commands to be stored in the buffer without them being written to the terminal.
#[macro_export]
macro_rules! queue {
($write:expr, $($command:expr), *) => {{
($write:expr, $($command:expr), * $(,)? ) => {{
// Silent warning when the macro is used inside the `command` module
#[allow(unused_imports)]
use $crate::Command;
@ -142,7 +142,7 @@ macro_rules! queue {
/// Because of that there is no difference between `execute` and `queue` for those windows versions.
#[macro_export]
macro_rules! execute {
($write:expr, $($command:expr), *) => {{
($write:expr, $($command:expr), * $(,)? ) => {{
// Silent warning when the macro is used inside the `command` module
#[allow(unused_imports)]
use $crate::{Command, write_cout};
@ -201,3 +201,39 @@ macro_rules! impl_from {
}
};
}
#[cfg(test)]
mod tests {
use std::io::{stdout, Write};
use crate::utils::command::Command;
#[cfg(windows)]
use crate::utils::error::ErrorKind;
pub struct FakeCommand;
impl Command for FakeCommand {
type AnsiType = &'static str;
fn ansi_code(&self) -> Self::AnsiType {
""
}
#[cfg(windows)]
fn execute_winapi(&self) -> Result<(), ErrorKind> {
Ok(())
}
}
#[test]
fn test_queue() {
assert!(queue!(stdout(), FakeCommand,).is_ok());
assert!(queue!(stdout(), FakeCommand).is_ok());
}
#[test]
fn test_execute() {
assert!(execute!(stdout(), FakeCommand,).is_ok());
assert!(execute!(stdout(), FakeCommand).is_ok());
}
}