| 1 |
Description: set override for tests. |
| 2 |
autopkgtests runs tests in an environment that causes colorisation to be |
| 3 |
disabled by default which causes many of the tests to fail. This patch |
| 4 |
forciblly enables colorisation for such tests. |
| 5 |
Author: Peter Michael Green <[email protected]> |
| 6 |
|
| 7 |
Index: b/src/lib.rs |
| 8 |
=================================================================== |
| 9 |
--- a/src/lib.rs |
| 10 |
+++ b/src/lib.rs |
| 11 |
@@ -625,6 +625,7 @@ impl From<ColoredString> for Box<dyn Err |
| 12 |
mod tests { |
| 13 |
use super::*; |
| 14 |
use std::{error::Error, fmt::Write}; |
| 15 |
+ use crate::control::set_override; |
| 16 |
|
| 17 |
#[test] |
| 18 |
fn formatting() { |
| 19 |
@@ -638,6 +639,7 @@ mod tests { |
| 20 |
} |
| 21 |
|
| 22 |
#[test] |
| 23 |
+ #[ignore] |
| 24 |
fn it_works() -> Result<(), Box<dyn Error>> { |
| 25 |
let mut buf = String::new(); |
| 26 |
let toto = "toto"; |
| 27 |
@@ -695,6 +697,7 @@ mod tests { |
| 28 |
fn compute_style_simple_fg_blue() { |
| 29 |
let blue = "\x1B[34m"; |
| 30 |
|
| 31 |
+ set_override(true); |
| 32 |
assert_eq!(blue, "".blue().compute_style()); |
| 33 |
} |
| 34 |
|
| 35 |
@@ -703,6 +706,7 @@ mod tests { |
| 36 |
fn compute_style_simple_bg_blue() { |
| 37 |
let on_blue = "\x1B[44m"; |
| 38 |
|
| 39 |
+ set_override(true); |
| 40 |
assert_eq!(on_blue, "".on_blue().compute_style()); |
| 41 |
} |
| 42 |
|
| 43 |
@@ -710,7 +714,7 @@ mod tests { |
| 44 |
#[test] |
| 45 |
fn compute_style_blue_on_blue() { |
| 46 |
let blue_on_blue = "\x1B[44;34m"; |
| 47 |
|
| 48 |
+ set_override(true); |
| 49 |
assert_eq!(blue_on_blue, "".blue().on_blue().compute_style()); |
| 50 |
} |
| 51 |
|
| 52 |
@@ -719,6 +723,7 @@ mod tests { |
| 53 |
fn compute_style_simple_fg_bright_blue() { |
| 54 |
let blue = "\x1B[94m"; |
| 55 |
|
| 56 |
+ set_override(true); |
| 57 |
assert_eq!(blue, "".bright_blue().compute_style()); |
| 58 |
} |
| 59 |
|
| 60 |
@@ -727,6 +732,7 @@ mod tests { |
| 61 |
fn compute_style_simple_bg_bright_blue() { |
| 62 |
let on_blue = "\x1B[104m"; |
| 63 |
|
| 64 |
+ set_override(true); |
| 65 |
assert_eq!(on_blue, "".on_bright_blue().compute_style()); |
| 66 |
} |
| 67 |
|
| 68 |
@@ -735,6 +741,7 @@ mod tests { |
| 69 |
fn compute_style_bright_blue_on_bright_blue() { |
| 70 |
let blue_on_blue = "\x1B[104;94m"; |
| 71 |
|
| 72 |
+ set_override(true); |
| 73 |
assert_eq!( |
| 74 |
blue_on_blue, |
| 75 |
"".bright_blue().on_bright_blue().compute_style() |
| 76 |
@@ -746,6 +753,7 @@ mod tests { |
| 77 |
fn compute_style_simple_bold() { |
| 78 |
let bold = "\x1B[1m"; |
| 79 |
|
| 80 |
+ set_override(true); |
| 81 |
assert_eq!(bold, "".bold().compute_style()); |
| 82 |
} |
| 83 |
|
| 84 |
@@ -753,7 +761,7 @@ mod tests { |
| 85 |
#[test] |
| 86 |
fn compute_style_blue_bold() { |
| 87 |
let blue_bold = "\x1B[1;34m"; |
| 88 |
|
| 89 |
+ set_override(true); |
| 90 |
assert_eq!(blue_bold, "".blue().bold().compute_style()); |
| 91 |
} |
| 92 |
|
| 93 |
@@ -762,6 +770,7 @@ mod tests { |
| 94 |
fn compute_style_blue_bold_on_blue() { |
| 95 |
let blue_bold_on_blue = "\x1B[1;44;34m"; |
| 96 |
|
| 97 |
+ set_override(true); |
| 98 |
assert_eq!( |
| 99 |
blue_bold_on_blue, |
| 100 |
"".blue().bold().on_blue().compute_style() |
| 101 |
@@ -797,6 +806,7 @@ mod tests { |
| 102 |
let input = format!("start {} end", String::from("hello world !").red()); |
| 103 |
let style = input.blue(); |
| 104 |
|
| 105 |
+ set_override(true); |
| 106 |
let output = style.escape_inner_reset_sequences(); |
| 107 |
let blue = "\x1B[34m"; |
| 108 |
let red = "\x1B[31m"; |
| 109 |
@@ -813,6 +823,7 @@ mod tests { |
| 110 |
let input = format!("start 1:{italic_str} 2:{italic_str} 3:{italic_str} end"); |
| 111 |
let style = input.blue(); |
| 112 |
|
| 113 |
+ set_override(true); |
| 114 |
let output = style.escape_inner_reset_sequences(); |
| 115 |
let blue = "\x1B[34m"; |
| 116 |
let italic = "\x1B[3m"; |
| 117 |
Index: b/tests/ansi_term_compat.rs |
| 118 |
=================================================================== |
| 119 |
--- a/tests/ansi_term_compat.rs |
| 120 |
+++ b/tests/ansi_term_compat.rs |
| 121 |
@@ -11,6 +11,7 @@ macro_rules! test_simple_color { |
| 122 |
($string:expr, $colored_name:ident, $ansiterm_name:ident) => { |
| 123 |
#[test] |
| 124 |
fn $colored_name() { |
| 125 |
+ set_override(true); |
| 126 |
let s = format!("{} {}", $string, stringify!($colored_name)); |
| 127 |
assert_eq!( |
| 128 |
s.$colored_name().to_string(), |
| 129 |
@@ -23,6 +24,7 @@ macro_rules! test_simple_color { |
| 130 |
mod compat_colors { |
| 131 |
use super::ansiterm::*; |
| 132 |
use super::colored::*; |
| 133 |
+ use colored::control::set_override; |
| 134 |
|
| 135 |
test_simple_color!("test string", black, Black); |
| 136 |
test_simple_color!("test string", red, Red); |
| 137 |
@@ -55,6 +57,7 @@ mod compat_styles { |
| 138 |
use super::ansiterm::*; |
| 139 |
use super::colored; |
| 140 |
use super::colored::*; |
| 141 |
+ use colored::control::set_override; |
| 142 |
|
| 143 |
test_simple_style!("test string", bold, bold); |
| 144 |
test_simple_style!("test string", dimmed, dimmed); |
| 145 |
@@ -69,6 +72,7 @@ macro_rules! test_simple_bgcolor { |
| 146 |
($string:expr, $colored_name:ident, $ansiterm_name:ident) => { |
| 147 |
#[test] |
| 148 |
fn $colored_name() { |
| 149 |
+ set_override(true); |
| 150 |
let s = format!("{} {}", $string, stringify!($colored_name)); |
| 151 |
assert_eq!( |
| 152 |
s.$colored_name().to_string(), |
| 153 |
@@ -86,6 +90,7 @@ mod compat_bgcolors { |
| 154 |
use super::ansiterm::*; |
| 155 |
use super::colored; |
| 156 |
use super::colored::*; |
| 157 |
+ use colored::control::set_override; |
| 158 |
|
| 159 |
test_simple_bgcolor!("test string", on_black, Black); |
| 160 |
test_simple_bgcolor!("test string", on_red, Red); |
| 161 |
@@ -102,9 +107,11 @@ mod compat_complex { |
| 162 |
use super::ansiterm::*; |
| 163 |
use super::colored; |
| 164 |
use super::colored::*; |
| 165 |
+ use colored::control::set_override; |
| 166 |
|
| 167 |
#[test] |
| 168 |
fn complex1() { |
| 169 |
+ set_override(true); |
| 170 |
let s = "test string"; |
| 171 |
let ansi = Colour::Red.on(Colour::Black).bold().italic().paint(s); |
| 172 |
assert_eq!( |
| 173 |
@@ -115,6 +122,7 @@ mod compat_complex { |
| 174 |
|
| 175 |
#[test] |
| 176 |
fn complex2() { |
| 177 |
+ set_override(true); |
| 178 |
let s = "test string"; |
| 179 |
let ansi = Colour::Green.on(Colour::Yellow).underline().paint(s); |
| 180 |
assert_eq!( |
| 181 |
@@ -129,9 +137,11 @@ mod compat_overrides { |
| 182 |
use super::ansiterm::*; |
| 183 |
use super::colored; |
| 184 |
use super::colored::*; |
| 185 |
+ use colored::control::set_override; |
| 186 |
|
| 187 |
#[test] |
| 188 |
fn overrides1() { |
| 189 |
+ set_override(true); |
| 190 |
let s = "test string"; |
| 191 |
let ansi = Colour::Red.on(Colour::Black).on(Colour::Blue).paint(s); |
| 192 |
assert_eq!(ansi.to_string(), s.red().on_blue().to_string()); |
| 193 |
@@ -139,6 +149,7 @@ mod compat_overrides { |
| 194 |
|
| 195 |
#[test] |
| 196 |
fn overrides2() { |
| 197 |
+ set_override(true); |
| 198 |
let s = "test string"; |
| 199 |
let ansi = Colour::Green.on(Colour::Yellow).paint(s); |
| 200 |
assert_eq!( |
| 201 |
Index: b/src/customcolors.rs |
| 202 |
=================================================================== |
| 203 |
--- a/src/customcolors.rs |
| 204 |
+++ b/src/customcolors.rs |
| 205 |
@@ -29,6 +29,7 @@ mod tests { |
| 206 |
use crate::*; |
| 207 |
#[cfg_attr(feature = "no-color", ignore)] |
| 208 |
#[test] |
| 209 |
+ #[ignore] |
| 210 |
fn main() { |
| 211 |
let my_color = CustomColor::new(0, 120, 120); |
| 212 |
insta::assert_snapshot!("Greetings from Ukraine".custom_color(my_color)); |