Skip to content

Commit

Permalink
Pick a stable error message date for ui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 27, 2020
1 parent 2449cbc commit 3f64062
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/time.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::date::Date;
use std::env;
use std::time::{SystemTime, UNIX_EPOCH};

// Timestamp of 2016-03-01 00:00:00 in UTC.
Expand All @@ -13,14 +14,20 @@ const DAYS_BY_MONTH: [u8; 12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

pub fn today() -> Date {
let default = Date {
year: 2019,
month: 1,
day: 1,
year: 2020,
month: 2,
day: 25,
};
try_today().unwrap_or(default)
}

fn try_today() -> Option<Date> {
if let Some(pkg_name) = env::var_os("CARGO_PKG_NAME") {
if pkg_name.to_str() == Some("rustversion-tests") {
return None; // Stable date for ui testing.
}
}

let now = SystemTime::now();
let since_epoch = now.duration_since(UNIX_EPOCH).ok()?;
let secs = since_epoch.as_secs();
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/bad-bound.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: expected rustc release number like 1.31, or nightly date like 2020-10-26
error: expected rustc release number like 1.31, or nightly date like 2020-02-25
--> $DIR/bad-bound.rs:1:22
|
1 | #[rustversion::since(stable)]
| ^^^^^^

error: expected rustc release number like 1.31, or nightly date like 2020-10-26
error: expected rustc release number like 1.31, or nightly date like 2020-02-25
--> $DIR/bad-bound.rs:4:26
|
4 | #[rustversion::any(since(stable))]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/bad-date.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: expected nightly date, like 2020-10-26
error: expected nightly date, like 2020-02-25
--> $DIR/bad-date.rs:1:24
|
1 | #[rustversion::nightly(stable)]
| ^^^^^^

error: expected nightly date, like 2020-10-26
error: expected nightly date, like 2020-02-25
--> $DIR/bad-date.rs:4:28
|
4 | #[rustversion::any(nightly(stable))]
Expand Down

0 comments on commit 3f64062

Please sign in to comment.