diff options
author | Joe Wilm <joe@jwilm.com> | 2016-11-19 16:16:20 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-11-19 21:34:11 -0800 |
commit | 66dbd29cd194a4c84f796f32827429895c2a3bba (patch) | |
tree | 5f5322cdae53d4fc295fe85f519192e9d38aab03 /src/event_loop.rs | |
parent | d97996e19de6856c23c51d05ec10f10db41e309d (diff) | |
download | alacritty-66dbd29cd194a4c84f796f32827429895c2a3bba.tar.gz alacritty-66dbd29cd194a4c84f796f32827429895c2a3bba.zip |
Add support for recording/running ref tests
Ref tests use a recording of the terminal protocol and a serialization
of the grid state to check that the parsing and action handling systems
produce the correct result. Ref tests may be recorded by running
alacritty with `--ref-test` and closing the terminal by using the window
"X" button. At that point, the recording is fully written to disk, and a
serialization of important state is recorded. Those files should be
moved to an appropriate folder in the `tests/ref/` tree, and the
`ref_test!` macro invocation should be updated accordingly.
A couple of changes were necessary to make this work:
* Ref tests shouldn't create a pty; the pty was refactored out of the
`Term` type.
* Repeatable lines/cols were needed; on startup, the terminal is resized
* by default to 80x24 though that may be changed by passing
`--dimensions w h`.
* Calculating window size based on desired rows/columns and font metrics
required making load_font callable multiple times.
* Refactor types into library crate so they may be imported in an
integration test.
* A whole bunch of types needed symmetric serialization and
deserialization. Mostly this was just adding derives, but the custom
deserialization of Rgb had to change to a deserialize_with function.
This initially adds one ref test as a sanity check, and more will be
added in subsequent commits. This initial ref tests just starts the
terminal and runs `ll`.
Diffstat (limited to 'src/event_loop.rs')
-rw-r--r-- | src/event_loop.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/event_loop.rs b/src/event_loop.rs index 7c00dd36..632ad28e 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -1,7 +1,8 @@ //! The main event loop which performs I/O on the pseudoterminal use std::borrow::Cow; use std::collections::VecDeque; -use std::io::{self, ErrorKind}; +use std::io::{self, ErrorKind, Write}; +use std::fs::File; use std::os::unix::io::AsRawFd; use std::sync::Arc; @@ -34,6 +35,7 @@ pub struct EventLoop<Io> { terminal: Arc<FairMutex<Term>>, proxy: ::glutin::WindowProxy, signal_flag: Flag, + ref_test: bool, } /// Helper type which tracks how much of a buffer has been written. @@ -130,6 +132,7 @@ impl<Io> EventLoop<Io> proxy: ::glutin::WindowProxy, signal_flag: Flag, pty: Io, + ref_test: bool, ) -> EventLoop<Io> { let (tx, rx) = ::mio::channel::channel(); EventLoop { @@ -139,7 +142,8 @@ impl<Io> EventLoop<Io> rx: rx, terminal: terminal, proxy: proxy, - signal_flag: signal_flag + signal_flag: signal_flag, + ref_test: ref_test, } } @@ -174,11 +178,15 @@ impl<Io> EventLoop<Io> } #[inline] - fn pty_read(&mut self, state: &mut State, buf: &mut [u8]) { + fn pty_read<W: Write>(&mut self, state: &mut State, buf: &mut [u8], mut writer: Option<&mut W>) { loop { match self.pty.read(&mut buf[..]) { Ok(0) => break, Ok(got) => { + writer = writer.map(|w| { + w.write_all(&buf[..got]).unwrap(); w + }); + let mut terminal = self.terminal.lock(); for byte in &buf[..got] { state.parser.advance(&mut *terminal, *byte); @@ -252,6 +260,14 @@ impl<Io> EventLoop<Io> let mut events = Events::with_capacity(1024); + let mut pipe = if self.ref_test { + let file = File::create("./alacritty.recording") + .expect("create alacritty recording"); + Some(file) + } else { + None + }; + 'event_loop: loop { self.poll.poll(&mut events, None).expect("poll ok"); @@ -262,7 +278,7 @@ impl<Io> EventLoop<Io> let kind = event.kind(); if kind.is_readable() { - self.pty_read(&mut state, &mut buf); + self.pty_read(&mut state, &mut buf, pipe.as_mut()); if ::tty::process_should_exit() { break 'event_loop; } |