summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-05-15 22:36:14 +0200
committerJoe Wilm <joe@jwilm.com>2018-06-02 09:56:50 -0700
commitac93f6d03198c1826dbed60fa8283aeb8d1a577d (patch)
tree3cb42b2e911abe85994643359cb12ee634aad820 /tests
parent6cddceb6cde032a79253f0596850c3e3c1c66db7 (diff)
Truncate invisible lines before storing ref-tests
Because there is no good way to store invisible lines in a backwards- and forwards-compatible way, they buffer now gets truncated before dumping the state of a grid when creating a ref-test. This involved a few workaround of which a few required adding additional methods which are only used in ref-tests, these should be minimal though. Since this required the creation of a truncation method anyways, some logic has been added which automatically truncates the invisible buffer when there are more than X (set to 100) invisible lines. This should not impact performance because it rarely occurs, but it could save a bit of memory when the history size is shrunk during runtime (see #1293). This also adds an optional `config.json` file to the ref-test output where it is possible to manually specify variables which should override config defaults, this has been used only for history_size so far. Creating a new ref-test does also still work, so there was no regression here, if history size is altered, the config.json just has to be created manually with the content `{"history_size":HIST_SIZE}`, where `HIST_SIZE` is the desired history size.
Diffstat (limited to 'tests')
-rw-r--r--tests/ref.rs32
-rw-r--r--tests/ref/grid_reset/config.json1
-rw-r--r--tests/ref/history/config.json1
3 files changed, 24 insertions, 10 deletions
diff --git a/tests/ref.rs b/tests/ref.rs
index 9ea0b80c..74cac6fa 100644
--- a/tests/ref.rs
+++ b/tests/ref.rs
@@ -1,5 +1,7 @@
-extern crate alacritty;
+#[macro_use]
+extern crate serde_derive;
extern crate serde_json as json;
+extern crate alacritty;
use std::fs::File;
use std::io::{self, Read};
@@ -61,26 +63,32 @@ fn read_u8<P>(path: P) -> Vec<u8>
res
}
-fn read_string<P>(path: P) -> String
+fn read_string<P>(path: P) -> Result<String, ::std::io::Error>
where P: AsRef<Path>
{
let mut res = String::new();
- File::open(path.as_ref()).unwrap()
- .read_to_string(&mut res).unwrap();
+ File::open(path.as_ref()).and_then(|mut f| f.read_to_string(&mut res))?;
- res
+ Ok(res)
+}
+
+#[derive(Deserialize, Default)]
+struct RefConfig {
+ history_size: u32,
}
fn ref_test(dir: &Path) {
let recording = read_u8(dir.join("alacritty.recording"));
- let serialized_size = read_string(dir.join("size.json"));
- let serialized_grid = read_string(dir.join("grid.json"));
+ let serialized_size = read_string(dir.join("size.json")).unwrap();
+ let serialized_grid = read_string(dir.join("grid.json")).unwrap();
+ let serialized_cfg = read_string(dir.join("config.json")).unwrap_or_default();
let size: SizeInfo = json::from_str(&serialized_size).unwrap();
let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
+ let ref_config: RefConfig = json::from_str(&serialized_cfg).unwrap_or_default();
let mut config: Config = Default::default();
- config.set_history((grid.len() - grid.num_lines().0) as u32);
+ config.set_history(ref_config.history_size);
let mut terminal = Term::new(&config, size);
let mut parser = ansi::Processor::new();
@@ -89,7 +97,11 @@ fn ref_test(dir: &Path) {
parser.advance(&mut terminal, byte, &mut io::sink());
}
- if grid != *terminal.grid() {
+ // Truncate invisible lines from the grid
+ let mut term_grid = terminal.grid().clone();
+ term_grid.truncate();
+
+ if grid != term_grid {
for i in 0..grid.len() {
for j in 0..grid.num_cols().0 {
let cell = terminal.grid()[i][Column(j)];
@@ -104,5 +116,5 @@ fn ref_test(dir: &Path) {
panic!("Ref test failed; grid doesn't match");
}
- assert_eq!(grid, *terminal.grid());
+ assert_eq!(grid, term_grid);
}
diff --git a/tests/ref/grid_reset/config.json b/tests/ref/grid_reset/config.json
new file mode 100644
index 00000000..e794493c
--- /dev/null
+++ b/tests/ref/grid_reset/config.json
@@ -0,0 +1 @@
+{"history_size":100}
diff --git a/tests/ref/history/config.json b/tests/ref/history/config.json
new file mode 100644
index 00000000..5cca8022
--- /dev/null
+++ b/tests/ref/history/config.json
@@ -0,0 +1 @@
+{"history_size":1000}