| 1 | //! Define custom test flags not natively supported by ui_test |
| 2 | |
| 3 | use crate::{ |
| 4 | build_manager::BuildManager, parser::Comments, per_test_config::TestConfig, Config, Errored, |
| 5 | }; |
| 6 | use std::{ |
| 7 | panic::{RefUnwindSafe, UnwindSafe}, |
| 8 | process::{Command, Output}, |
| 9 | }; |
| 10 | |
| 11 | #[cfg (feature = "rustc" )] |
| 12 | pub mod edition; |
| 13 | #[cfg (feature = "rustc" )] |
| 14 | pub mod revision_args; |
| 15 | #[cfg (feature = "rustc" )] |
| 16 | pub mod run; |
| 17 | pub mod rustfix; |
| 18 | |
| 19 | /// Tester-specific flag that gets parsed from `//@` comments. |
| 20 | pub trait Flag: Send + Sync + UnwindSafe + RefUnwindSafe + std::fmt::Debug { |
| 21 | /// Clone the boxed value and create a new box. |
| 22 | fn clone_inner(&self) -> Box<dyn Flag>; |
| 23 | |
| 24 | /// Modify a command to what the flag specifies |
| 25 | fn apply( |
| 26 | &self, |
| 27 | _cmd: &mut Command, |
| 28 | _config: &TestConfig, |
| 29 | _build_manager: &BuildManager, |
| 30 | ) -> Result<(), Errored> { |
| 31 | Ok(()) |
| 32 | } |
| 33 | |
| 34 | /// Whether this flag causes a test to be filtered out |
| 35 | fn test_condition(&self, _config: &Config, _comments: &Comments, _revision: &str) -> bool { |
| 36 | false |
| 37 | } |
| 38 | |
| 39 | /// Run an action after a test is finished. |
| 40 | /// Returns an empty [`Vec`] if no action was taken. |
| 41 | fn post_test_action( |
| 42 | &self, |
| 43 | _config: &TestConfig, |
| 44 | _output: &Output, |
| 45 | _build_manager: &BuildManager, |
| 46 | ) -> Result<(), Errored> { |
| 47 | Ok(()) |
| 48 | } |
| 49 | |
| 50 | /// Whether the flag gets overridden by the same flag in revisions. |
| 51 | fn must_be_unique(&self) -> bool; |
| 52 | } |
| 53 | |
| 54 | /// Use the unit type for when you don't need any behaviour and just need to know if the flag was set or not. |
| 55 | impl Flag for () { |
| 56 | fn clone_inner(&self) -> Box<dyn Flag> { |
| 57 | Box::new(()) |
| 58 | } |
| 59 | fn must_be_unique(&self) -> bool { |
| 60 | true |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | impl Clone for Box<dyn Flag> { |
| 65 | fn clone(&self) -> Self { |
| 66 | self.clone_inner() |
| 67 | } |
| 68 | } |
| 69 | |