1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-03 04:34:21 -05:00

Enable history comparison in ref-tests

Previously ref-tests just ignored the scrollback history to keep
the old tests working, this would lead to new tests which rely on
scrollback history to succeeed even though they should not.

This has been fixed and it is now possible to create ref-tests with and
without scrollback history. When available the scrollback history is
compared, but the old tests still work without having to adjust them.

This fixes #1244.
This commit is contained in:
Christian Duerr 2018-04-14 17:21:48 +02:00 committed by Joe Wilm
parent d8bda60c3d
commit 2234234ca9
6 changed files with 50039 additions and 17 deletions

View file

@ -1431,6 +1431,11 @@ impl Config {
self.scrolling
}
// Update the history size, used in ref tests
pub fn set_history(&mut self, history: u32) {
self.scrolling.history = history;
}
pub fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
let path = path.into();
let raw = Config::read_file(path.as_path())?;

View file

@ -52,9 +52,23 @@ impl<T> Deref for Indexed<T> {
impl<T: PartialEq> ::std::cmp::PartialEq for Grid<T> {
fn eq(&self, other: &Self) -> bool {
// Compare raw grid content
// TODO: This is pretty inefficient but only used in tests
let mut raw_match = true;
for i in 0..(self.lines.0 + self.history_size) {
for j in 0..self.cols.0 {
if self[i][Column(j)] != other[i][Column(j)] {
raw_match = false;
break;
}
}
}
// Compare struct fields and check result of grid comparison
self.cols.eq(&other.cols) &&
self.lines.eq(&other.lines) &&
self.raw.eq(&other.raw)
self.history_size.eq(&other.history_size) &&
raw_match
}
}
@ -88,6 +102,10 @@ pub struct Grid<T> {
/// Selected region
#[serde(skip)]
pub selection: Option<Selection>,
/// Maximum number of lines in the scrollback history
#[serde(default)]
history_size: usize,
}
pub struct GridIterator<'a, T: 'a> {
@ -132,6 +150,7 @@ impl<T: Copy + Clone> Grid<T> {
display_offset: 0,
scroll_limit: 0,
selection: None,
history_size: scrollback,
}
}

View file

@ -22,16 +22,6 @@ pub struct Storage<T> {
visible_lines: Line,
}
impl<T: PartialEq> ::std::cmp::PartialEq for Storage<T> {
fn eq(&self, other: &Self) -> bool {
let mut equal = true;
for i in IndexRange(Line(0) .. self.visible_lines) {
equal = equal && (self[i] == other[i])
}
equal
}
}
impl<T> Storage<T> {
#[inline]
pub fn with_capacity(cap: usize, lines: Line) -> Storage<T> {

View file

@ -9,10 +9,11 @@ use alacritty::Grid;
use alacritty::grid::IndexRegion;
use alacritty::Term;
use alacritty::ansi;
use alacritty::index::{Line, Column};
use alacritty::index::Column;
use alacritty::term::Cell;
use alacritty::term::SizeInfo;
use alacritty::util::fmt::{Red, Green};
use alacritty::config::Config;
macro_rules! ref_tests {
($($name:ident)*) => {
@ -47,6 +48,7 @@ ref_tests! {
vttest_scroll
vttest_tab_clear_set
zsh_tab_completion
history
}
fn read_u8<P>(path: P) -> Vec<u8>
@ -77,7 +79,10 @@ fn ref_test(dir: &Path) {
let size: SizeInfo = json::from_str(&serialized_size).unwrap();
let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
let mut terminal = Term::new(&Default::default(), size);
let mut config: Config = Default::default();
config.set_history(grid.history_size() as u32);
let mut terminal = Term::new(&config, size);
let mut parser = ansi::Processor::new();
for byte in recording {
@ -85,10 +90,11 @@ fn ref_test(dir: &Path) {
}
if grid != *terminal.grid() {
for (i, row) in terminal.grid().region(..).into_iter().enumerate() {
for (j, cell) in row.iter().enumerate() {
let original_cell = &grid[Line(i)][Column(j)];
if *original_cell != *cell {
for i in 0..(grid.num_lines().0 + grid.history_size()) {
for j in 0..grid.num_cols().0 {
let cell = terminal.grid()[i][Column(j)];
let original_cell = grid[i][Column(j)];
if original_cell != cell {
println!("[{i}][{j}] {original:?} => {now:?}",
i=i, j=j, original=Green(original_cell), now=Red(cell));
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
{"width":2532.0,"height":1380.0,"cell_width":10.0,"cell_height":19.0,"padding_x":5.0,"padding_y":5.0}