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:
parent
d8bda60c3d
commit
2234234ca9
|
@ -1431,6 +1431,11 @@ impl Config {
|
||||||
self.scrolling
|
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> {
|
pub fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
let raw = Config::read_file(path.as_path())?;
|
let raw = Config::read_file(path.as_path())?;
|
||||||
|
|
|
@ -52,9 +52,23 @@ impl<T> Deref for Indexed<T> {
|
||||||
|
|
||||||
impl<T: PartialEq> ::std::cmp::PartialEq for Grid<T> {
|
impl<T: PartialEq> ::std::cmp::PartialEq for Grid<T> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
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.cols.eq(&other.cols) &&
|
||||||
self.lines.eq(&other.lines) &&
|
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
|
/// Selected region
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub selection: Option<Selection>,
|
pub selection: Option<Selection>,
|
||||||
|
|
||||||
|
/// Maximum number of lines in the scrollback history
|
||||||
|
#[serde(default)]
|
||||||
|
history_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridIterator<'a, T: 'a> {
|
pub struct GridIterator<'a, T: 'a> {
|
||||||
|
@ -132,6 +150,7 @@ impl<T: Copy + Clone> Grid<T> {
|
||||||
display_offset: 0,
|
display_offset: 0,
|
||||||
scroll_limit: 0,
|
scroll_limit: 0,
|
||||||
selection: None,
|
selection: None,
|
||||||
|
history_size: scrollback,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,16 +22,6 @@ pub struct Storage<T> {
|
||||||
visible_lines: Line,
|
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> {
|
impl<T> Storage<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_capacity(cap: usize, lines: Line) -> Storage<T> {
|
pub fn with_capacity(cap: usize, lines: Line) -> Storage<T> {
|
||||||
|
|
18
tests/ref.rs
18
tests/ref.rs
|
@ -9,10 +9,11 @@ use alacritty::Grid;
|
||||||
use alacritty::grid::IndexRegion;
|
use alacritty::grid::IndexRegion;
|
||||||
use alacritty::Term;
|
use alacritty::Term;
|
||||||
use alacritty::ansi;
|
use alacritty::ansi;
|
||||||
use alacritty::index::{Line, Column};
|
use alacritty::index::Column;
|
||||||
use alacritty::term::Cell;
|
use alacritty::term::Cell;
|
||||||
use alacritty::term::SizeInfo;
|
use alacritty::term::SizeInfo;
|
||||||
use alacritty::util::fmt::{Red, Green};
|
use alacritty::util::fmt::{Red, Green};
|
||||||
|
use alacritty::config::Config;
|
||||||
|
|
||||||
macro_rules! ref_tests {
|
macro_rules! ref_tests {
|
||||||
($($name:ident)*) => {
|
($($name:ident)*) => {
|
||||||
|
@ -47,6 +48,7 @@ ref_tests! {
|
||||||
vttest_scroll
|
vttest_scroll
|
||||||
vttest_tab_clear_set
|
vttest_tab_clear_set
|
||||||
zsh_tab_completion
|
zsh_tab_completion
|
||||||
|
history
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_u8<P>(path: P) -> Vec<u8>
|
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 size: SizeInfo = json::from_str(&serialized_size).unwrap();
|
||||||
let grid: Grid<Cell> = json::from_str(&serialized_grid).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();
|
let mut parser = ansi::Processor::new();
|
||||||
|
|
||||||
for byte in recording {
|
for byte in recording {
|
||||||
|
@ -85,10 +90,11 @@ fn ref_test(dir: &Path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if grid != *terminal.grid() {
|
if grid != *terminal.grid() {
|
||||||
for (i, row) in terminal.grid().region(..).into_iter().enumerate() {
|
for i in 0..(grid.num_lines().0 + grid.history_size()) {
|
||||||
for (j, cell) in row.iter().enumerate() {
|
for j in 0..grid.num_cols().0 {
|
||||||
let original_cell = &grid[Line(i)][Column(j)];
|
let cell = terminal.grid()[i][Column(j)];
|
||||||
if *original_cell != *cell {
|
let original_cell = grid[i][Column(j)];
|
||||||
|
if original_cell != cell {
|
||||||
println!("[{i}][{j}] {original:?} => {now:?}",
|
println!("[{i}][{j}] {original:?} => {now:?}",
|
||||||
i=i, j=j, original=Green(original_cell), now=Red(cell));
|
i=i, j=j, original=Green(original_cell), now=Red(cell));
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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}
|
Loading…
Reference in New Issue