Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute all tests on CI + warnings/errors cleanup #216

Merged
merged 19 commits into from
Sep 15, 2019
27 changes: 20 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
# Set up the Rust toolchain.
language: rust

rust:
- stable

before_script:
- export PATH=$PATH:/home/travis/.cargo/bin
- rustup component add rustfmt-preview
- nightly

os:
- linux
- osx
- windows
- osx

git:
depth: 1
quiet: true

matrix:
allow_failures:
- rust: nightly

before_script:
- export PATH=$PATH:/home/travis/.cargo/bin
- rustup component add rustfmt

script:
- cargo fmt --version
- rustup --version
- rustc --version
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then cargo fmt --all -- --check; fi
- cargo build
- cargo fmt -- --check
- cargo test -- --nocapture --test-threads 1
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then cargo test --all -- --nocapture --test-threads 1; else cargo test --all --exclude crossterm_winapi -- --nocapture --test-threads 1; fi
12 changes: 10 additions & 2 deletions crossterm_cursor/src/cursor/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ mod winapi_tests {
}

/* ======================== ANSI =========================== */
// TODO - Test is ingored, because it's stalled on Travis CI
#[test]
#[ignore]
fn reset_safe_ansi() {
if try_enable_ansi() {
let cursor = AnsiCursor::new();
Expand All @@ -53,13 +55,19 @@ fn reset_safe_ansi() {
}
}

// TODO - Test is ingored, because it's stalled on Travis CI
#[test]
#[ignore]
fn goto_ansi() {
if try_enable_ansi() {
let cursor = AnsiCursor::new();
let (x_saved, y_saved) = cursor.pos();

cursor.goto(5, 5);
let (x, y) = cursor.pos();

cursor.goto(x_saved, y_saved);

assert_eq!(x, 5);
assert_eq!(y, 5);
}
Expand All @@ -74,10 +82,10 @@ fn try_enable_ansi() -> bool {
// if it is not listed we should try with WinApi to check if we do support ANSI-codes.
match set_virtual_terminal_processing(true) {
Ok(_) => return true,
Err(e) => return false,
Err(_) => return false,
}
}
}

return true;
true
}
20 changes: 10 additions & 10 deletions crossterm_cursor/src/sys/winapi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
//! This module handles some logic for cursor interaction in the windows console.

use std::io::{self, Result};

use winapi::{
shared::minwindef::{FALSE, TRUE},
um::wincon::{SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD},
um::winnt::HANDLE,
};

pub use crossterm_winapi::{is_true, Coord, Handle, HandleType, ScreenBuffer};

#[cfg(windows)]
pub fn get_cursor_position() -> (u16, u16) {
if let Ok(cursor) = Cursor::new() {
Expand All @@ -14,16 +24,6 @@ pub fn show_cursor(show_cursor: bool) -> Result<()> {
Cursor::from(Handle::current_out_handle()?).set_visibility(show_cursor)
}

pub use crossterm_winapi::{is_true, Coord, Handle, HandleType, ScreenBuffer};

use winapi::{
shared::minwindef::{FALSE, TRUE},
um::wincon::{SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD},
um::winnt::HANDLE,
};

use std::io::{self, Result};

/// This stores the cursor pos, at program level. So it can be recalled later.
static mut SAVED_CURSOR_POS: (u16, u16) = (0, 0);

Expand Down
26 changes: 13 additions & 13 deletions crossterm_input/src/input/windows_input.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! This is a WINDOWS specific implementation for input related action.

use super::*;

use crossterm_winapi::{
ButtonState, Console, ConsoleMode, EventFlags, Handle, InputEventType, KeyEventRecord,
MouseEvent,
};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::time::Duration;
use std::{char, io, thread};

use winapi::um::{
wincon::{
Expand All @@ -19,10 +17,12 @@ use winapi::um::{
},
};

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::time::Duration;
use std::{char, io, thread};
use crossterm_winapi::{
ButtonState, Console, ConsoleMode, EventFlags, Handle, InputEventType, KeyEventRecord,
MouseEvent,
};

use super::*;

pub struct WindowsInput;

Expand Down Expand Up @@ -157,7 +157,7 @@ pub struct AsyncReader {
impl AsyncReader {
/// Construct a new instance of the `AsyncReader`.
/// The reading will immediately start when calling this function.
pub fn new(function: Box<Fn(&Sender<InputEvent>, &Arc<AtomicBool>) + Send>) -> AsyncReader {
pub fn new(function: Box<dyn Fn(&Sender<InputEvent>, &Arc<AtomicBool>) + Send>) -> AsyncReader {
let shutdown_handle = Arc::new(AtomicBool::new(false));

let (event_tx, event_rx) = mpsc::channel();
Expand Down Expand Up @@ -383,10 +383,10 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option<KeyEvent> {
}
} else if key_state.has_state(LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) {
match character_raw as u8 {
c @ b'\x01'...b'\x1A' => {
c @ b'\x01'..=b'\x1A' => {
Some(KeyEvent::Ctrl((c as u8 - 0x1 + b'a') as char))
}
c @ b'\x1C'...b'\x1F' => {
c @ b'\x1C'..=b'\x1F' => {
Some(KeyEvent::Ctrl((c as u8 - 0x1C + b'4') as char))
}
_ => None,
Expand Down
3 changes: 2 additions & 1 deletion crossterm_terminal/src/terminal/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ impl Terminal {
self.terminal.set_size(width, height)
}

// TODO - Marked as no_run, because it's failing on Travis CI
/// Exit the current process.
///
/// ```rust
/// ```no_run
/// # use crossterm_terminal::terminal;
/// let mut term = terminal();
///
Expand Down
12 changes: 8 additions & 4 deletions crossterm_terminal/src/terminal/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* ======================== WinApi =========================== */
#[cfg(windows)]
mod winapi_tests {
use super::*;
use super::super::*;

// TODO - Test is ignored, because it returns wrong result (31 != 30)
#[test]
#[ignore]
fn resize_winapi() {
let terminal = WinApiTerminal::new();

terminal.set_size(30, 30);
terminal.set_size(30, 30).unwrap();

let (x, y) = terminal.terminal_size();

Expand All @@ -17,7 +19,9 @@ mod winapi_tests {
}

/* ======================== ANSI =========================== */
// TODO - Test is disabled, because it's failing on Travis CI
#[test]
#[ignore]
fn resize_ansi() {
use super::*;
use std::{thread, time};
Expand Down Expand Up @@ -45,10 +49,10 @@ fn try_enable_ansi() -> bool {
// if it is not listed we should try with WinApi to check if we do support ANSI-codes.
match set_virtual_terminal_processing(true) {
Ok(_) => return true,
Err(e) => return false,
Err(_) => return false,
}
}
}

return true;
true
}
19 changes: 0 additions & 19 deletions crossterm_winapi/.travis.yml

This file was deleted.

7 changes: 5 additions & 2 deletions crossterm_winapi/examples/coloring_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn set_background_color() -> std::io::Result<()> {
let fg_color = attrs & 0x0007;

// apply the blue background flag to the current attributes
let mut new_color = fg_color | BLUE_BACKGROUND;
let new_color = fg_color | BLUE_BACKGROUND;

// set the console text attribute to the new color value.
Console::from(**screen_buffer.get_handle()).set_text_attribute(new_color)?;
Expand Down Expand Up @@ -48,4 +48,7 @@ fn set_foreground_color() -> std::io::Result<()> {
Ok(())
}

fn main() {}
fn main() {
set_background_color().unwrap();
set_foreground_color().unwrap();
}
12 changes: 8 additions & 4 deletions crossterm_winapi/examples/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ extern crate crossterm_winapi;

use crossterm_winapi::ConsoleMode;

pub fn change_console_mode() {
fn change_console_mode() {
let console_mode = ConsoleMode::new().unwrap();

// get the current console mode:
let mode: u32 = console_mode.mode().unwrap();
let _mode: u32 = console_mode.mode().unwrap();

// set the console mode (not sure if this is an actual value xp)
console_mode.set_mode(10);
console_mode
.set_mode(10)
.expect("Unable to set console mode");
}

fn main() {}
fn main() {
change_console_mode();
}
3 changes: 2 additions & 1 deletion crossterm_winapi/examples/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ extern crate crossterm_winapi;

use crossterm_winapi::{Handle, HandleType};

#[allow(unused_variables)]
fn main() {
/// see the description of the types to see what they do.
// see the description of the types to see what they do.
let out_put_handle = Handle::new(HandleType::OutputHandle).unwrap();
let out_put_handle = Handle::new(HandleType::InputHandle).unwrap();
let curr_out_put_handle = Handle::new(HandleType::CurrentOutputHandle).unwrap();
Expand Down
11 changes: 7 additions & 4 deletions crossterm_winapi/examples/screen_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
extern crate crossterm_winapi;

use crossterm_winapi::{Handle, ScreenBuffer};

fn main() {}
use crossterm_winapi::ScreenBuffer;

fn print_screen_buffer_information() {
let screen_buffer = ScreenBuffer::current().unwrap();
Expand All @@ -16,10 +14,15 @@ fn print_screen_buffer_information() {
println!("terminal size {:?}", csbi.terminal_size());
}

#[allow(dead_code)]
fn multiple_screen_buffers() {
// create new screen buffer
let screen_buffer = ScreenBuffer::create();

// which to this screen buffer
screen_buffer.show();
screen_buffer.show().expect("Unable to show screen buffer");
}

fn main() {
print_screen_buffer_information();
}
9 changes: 5 additions & 4 deletions crossterm_winapi/src/console.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::{is_true, Coord, Handle, HandleType, WindowPositions};
use std::borrow::ToOwned;
use std::io::{self, Error, Result};
use std::str;

use std::borrow::ToOwned;
use winapi::ctypes::c_void;
use winapi::shared::minwindef::DWORD;
use winapi::shared::ntdef::NULL;
Expand All @@ -17,6 +16,8 @@ use winapi::um::{

use InputRecord;

use super::{is_true, Coord, Handle, HandleType, WindowPositions};

/// Could be used to do some basic things with the console.
pub struct Console {
handle: Handle,
Expand Down Expand Up @@ -165,7 +166,7 @@ impl Console {
}

pub fn read_single_input_event(&self) -> Result<Option<InputRecord>> {
let mut buf_len = self.number_of_console_input_events()?;
let buf_len = self.number_of_console_input_events()?;

// Fast-skipping all the code below if there is nothing to read at all
if buf_len == 0 {
Expand All @@ -182,7 +183,7 @@ impl Console {
}

pub fn read_console_input(&self) -> Result<(u32, Vec<InputRecord>)> {
let mut buf_len = self.number_of_console_input_events()?;
let buf_len = self.number_of_console_input_events()?;

// Fast-skipping all the code below if there is nothing to read at all
if buf_len == 0 {
Expand Down
8 changes: 5 additions & 3 deletions crossterm_winapi/src/console_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ impl From<Handle> for ConsoleMode {
mod test {
use super::ConsoleMode;

// TODO - Test is ignored, because it's failing on Travis CI
#[test]
#[ignore]
fn set_get_mode() {
let mode = ConsoleMode::new().unwrap();

let original_mode = mode.mode().unwrap();

mode.set_mode(0x0004);
assert!(mode.set_mode(0x0004).is_ok());
let console_mode = mode.mode().unwrap();

assert!((console_mode & 0x0004) != 0);
assert_ne!(console_mode & 0x0004, 0);

mode.set_mode(original_mode);
assert!(mode.set_mode(original_mode).is_ok());
}
}
Loading