Skip to content

test: skip terminfo parsing in Miri #100206

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

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions library/test/src/term/terminfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ impl TermInfo {

/// Creates a TermInfo for the named terminal.
pub(crate) fn from_name(name: &str) -> Result<TermInfo, Error> {
if cfg!(miri) {
// Avoid all the work of parsing the terminfo (it's pretty slow under Miri), and just
// assume that the standard color codes work (like e.g. the 'colored' crate).
return Ok(TermInfo {
names: Default::default(),
bools: Default::default(),
numbers: Default::default(),
strings: Default::default(),
});
}

get_dbpath_for_term(name)
.ok_or_else(|| {
Error::IoError(io::Error::new(io::ErrorKind::NotFound, "terminfo file not found"))
Expand Down Expand Up @@ -119,13 +130,22 @@ pub(crate) struct TerminfoTerminal<T> {
impl<T: Write + Send> Terminal for TerminfoTerminal<T> {
fn fg(&mut self, color: color::Color) -> io::Result<bool> {
let color = self.dim_if_necessary(color);
if cfg!(miri) && color < 8 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious to me what happens if color = 9. The logic for num_colors isn't totally straightforward, but I think in Miri we end up with num_colors = 0, right? Could we explain this in a comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah num_colors is always 0 in Miri. I added a comment.

// The Miri logic for this only works for the most basic 8 colors, which we just assume
// the terminal will support. (`num_colors` is always 0 in Miri, so higher colors will
// just fail. But libtest doesn't use any higher colors anyway.)
return write!(self.out, "\x1B[3{color}m").and(Ok(true));
}
if self.num_colors > color {
return self.apply_cap("setaf", &[Param::Number(color as i32)]);
}
Ok(false)
}

fn reset(&mut self) -> io::Result<bool> {
if cfg!(miri) {
return write!(self.out, "\x1B[0m").and(Ok(true));
}
// are there any terminals that have color/attrs and not sgr0?
// Try falling back to sgr, then op
let cmd = match ["sgr0", "sgr", "op"].iter().find_map(|cap| self.ti.strings.get(*cap)) {
Expand Down