From ed9d6e0c03b53aea602ea9b0a283b39491f73b91 Mon Sep 17 00:00:00 2001 From: Ryan Lowe Date: Sun, 28 Apr 2024 15:37:14 -0400 Subject: [PATCH] Move various stdlib tests to library/std/tests --- .../std/tests}/builtin-clone.rs | 4 ++-- .../std/tests}/eq-multidispatch.rs | 5 ++--- .../std/tests}/issue-21058.rs | 6 +++--- .../std/tests}/istr.rs | 15 +++++---------- .../log-knows-the-names-of-variants-in-std.rs | 6 +++--- .../std/tests}/minmax-stability-issue-23687.rs | 5 ++--- .../std/tests}/seq-compare.rs | 5 ++--- .../std/tests}/slice-from-array-issue-113238.rs | 5 ++--- .../std/tests}/volatile-fat-ptr.rs | 6 +++--- 9 files changed, 24 insertions(+), 33 deletions(-) rename {tests/ui/stdlib-unit-tests => library/std/tests}/builtin-clone.rs (96%) rename {tests/ui/stdlib-unit-tests => library/std/tests}/eq-multidispatch.rs (95%) rename {tests/ui/stdlib-unit-tests => library/std/tests}/issue-21058.rs (93%) rename {tests/ui/stdlib-unit-tests => library/std/tests}/istr.rs (86%) rename {tests/ui/stdlib-unit-tests => library/std/tests}/log-knows-the-names-of-variants-in-std.rs (90%) rename {tests/ui/stdlib-unit-tests => library/std/tests}/minmax-stability-issue-23687.rs (98%) rename {tests/ui/stdlib-unit-tests => library/std/tests}/seq-compare.rs (95%) rename {tests/ui/std => library/std/tests}/slice-from-array-issue-113238.rs (90%) rename {tests/ui/stdlib-unit-tests => library/std/tests}/volatile-fat-ptr.rs (90%) diff --git a/tests/ui/stdlib-unit-tests/builtin-clone.rs b/library/std/tests/builtin-clone.rs similarity index 96% rename from tests/ui/stdlib-unit-tests/builtin-clone.rs rename to library/std/tests/builtin-clone.rs index 47c00ede0e9..c5b3f4ebc12 100644 --- a/tests/ui/stdlib-unit-tests/builtin-clone.rs +++ b/library/std/tests/builtin-clone.rs @@ -1,4 +1,3 @@ -//@ run-pass // Test that `Clone` is correctly implemented for builtin types. // Also test that cloning an array or a tuple is done right, i.e. // each component is cloned. @@ -18,7 +17,8 @@ fn clone(&self) -> Self { } } -fn main() { +#[test] +fn builtin_clone() { test_clone(foo); test_clone([1; 56]); test_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)); diff --git a/tests/ui/stdlib-unit-tests/eq-multidispatch.rs b/library/std/tests/eq-multidispatch.rs similarity index 95% rename from tests/ui/stdlib-unit-tests/eq-multidispatch.rs rename to library/std/tests/eq-multidispatch.rs index 4a991624e34..6c98fa6a1bd 100644 --- a/tests/ui/stdlib-unit-tests/eq-multidispatch.rs +++ b/library/std/tests/eq-multidispatch.rs @@ -1,5 +1,3 @@ -//@ run-pass - #[derive(PartialEq, Debug)] struct Bar; #[derive(Debug)] @@ -17,7 +15,8 @@ impl PartialEq for Fu { fn eq(&self, _: &Foo) -> bool { true } } impl PartialEq for Foo { fn eq(&self, _: &Bar) -> bool { false } } impl PartialEq for Bar { fn eq(&self, _: &Foo) -> bool { false } } -fn main() { +#[test] +fn eq_multidispatch() { assert!(Bar != Foo); assert!(Foo != Bar); diff --git a/tests/ui/stdlib-unit-tests/issue-21058.rs b/library/std/tests/issue-21058.rs similarity index 93% rename from tests/ui/stdlib-unit-tests/issue-21058.rs rename to library/std/tests/issue-21058.rs index 0e04f1e21b8..0626c870d81 100644 --- a/tests/ui/stdlib-unit-tests/issue-21058.rs +++ b/library/std/tests/issue-21058.rs @@ -1,4 +1,3 @@ -//@ run-pass #![allow(dead_code)] use std::fmt::Debug; @@ -15,7 +14,8 @@ macro_rules! check { }; } -fn main() { +#[test] +fn issue_21058() { // type_name should support unsized types check!([u8], "[u8]"); check!(str, "str"); @@ -31,7 +31,7 @@ fn main() { ::fmt, "::fmt" ); - check!(val: || {}, "issue_21058::main::{{closure}}"); + check!(val: || {}, "issue_21058::issue_21058::{{closure}}"); bar::(); } diff --git a/tests/ui/stdlib-unit-tests/istr.rs b/library/std/tests/istr.rs similarity index 86% rename from tests/ui/stdlib-unit-tests/istr.rs rename to library/std/tests/istr.rs index f6298919425..b27eaf8f890 100644 --- a/tests/ui/stdlib-unit-tests/istr.rs +++ b/library/std/tests/istr.rs @@ -1,5 +1,4 @@ -//@ run-pass - +#[test] fn test_stack_assign() { let s: String = "a".to_string(); println!("{}", s.clone()); @@ -9,8 +8,10 @@ fn test_stack_assign() { assert!((s != u)); } +#[test] fn test_heap_lit() { "a big string".to_string(); } +#[test] fn test_heap_assign() { let s: String = "a big ol' string".to_string(); let t: String = "a big ol' string".to_string(); @@ -19,11 +20,13 @@ fn test_heap_assign() { assert!((s != u)); } +#[test] fn test_heap_log() { let s = "a big ol' string".to_string(); println!("{}", s); } +#[test] fn test_append() { let mut s = String::new(); s.push_str("a"); @@ -41,11 +44,3 @@ fn test_append() { s.push_str("&tea"); assert_eq!(s, "coffee&tea"); } - -pub fn main() { - test_stack_assign(); - test_heap_lit(); - test_heap_assign(); - test_heap_log(); - test_append(); -} diff --git a/tests/ui/stdlib-unit-tests/log-knows-the-names-of-variants-in-std.rs b/library/std/tests/log-knows-the-names-of-variants-in-std.rs similarity index 90% rename from tests/ui/stdlib-unit-tests/log-knows-the-names-of-variants-in-std.rs rename to library/std/tests/log-knows-the-names-of-variants-in-std.rs index 8f351b2b40b..82afc8b219e 100644 --- a/tests/ui/stdlib-unit-tests/log-knows-the-names-of-variants-in-std.rs +++ b/library/std/tests/log-knows-the-names-of-variants-in-std.rs @@ -1,7 +1,6 @@ -//@ run-pass - #![allow(non_camel_case_types)] #![allow(dead_code)] + #[derive(Clone, Debug)] enum foo { a(usize), @@ -12,7 +11,8 @@ fn check_log(exp: String, v: T) { assert_eq!(exp, format!("{:?}", v)); } -pub fn main() { +#[test] +fn log_knows_the_names_of_variants_in_std() { let mut x = Some(foo::a(22)); let exp = "Some(a(22))".to_string(); let act = format!("{:?}", x); diff --git a/tests/ui/stdlib-unit-tests/minmax-stability-issue-23687.rs b/library/std/tests/minmax-stability-issue-23687.rs similarity index 98% rename from tests/ui/stdlib-unit-tests/minmax-stability-issue-23687.rs rename to library/std/tests/minmax-stability-issue-23687.rs index bf42347df0b..dcc36826f21 100644 --- a/tests/ui/stdlib-unit-tests/minmax-stability-issue-23687.rs +++ b/library/std/tests/minmax-stability-issue-23687.rs @@ -1,5 +1,3 @@ -//@ run-pass - use std::fmt::Debug; use std::cmp::{self, Ordering}; @@ -21,7 +19,8 @@ fn cmp(&self, other: &Foo) -> Ordering { } } -fn main() { +#[test] +fn minmax_stability() { let a = Foo { n: 4, name: "a" }; let b = Foo { n: 4, name: "b" }; let c = Foo { n: 8, name: "c" }; diff --git a/tests/ui/stdlib-unit-tests/seq-compare.rs b/library/std/tests/seq-compare.rs similarity index 95% rename from tests/ui/stdlib-unit-tests/seq-compare.rs rename to library/std/tests/seq-compare.rs index 1be0569e17c..221f1c7cabd 100644 --- a/tests/ui/stdlib-unit-tests/seq-compare.rs +++ b/library/std/tests/seq-compare.rs @@ -1,6 +1,5 @@ -//@ run-pass - -pub fn main() { +#[test] +fn seq_compare() { assert!(("hello".to_string() < "hellr".to_string())); assert!(("hello ".to_string() > "hello".to_string())); assert!(("hello".to_string() != "there".to_string())); diff --git a/tests/ui/std/slice-from-array-issue-113238.rs b/library/std/tests/slice-from-array-issue-113238.rs similarity index 90% rename from tests/ui/std/slice-from-array-issue-113238.rs rename to library/std/tests/slice-from-array-issue-113238.rs index 44f2d7a9478..97aba4fec01 100644 --- a/tests/ui/std/slice-from-array-issue-113238.rs +++ b/library/std/tests/slice-from-array-issue-113238.rs @@ -1,9 +1,8 @@ -//@ check-pass - // This intends to use the unsizing coercion from array to slice, but it only // works if we resolve `<&[u8]>::from` as the reflexive `From for T`. In // #113238, we found that gimli had added its own `From for &[u8]` // that affected all `std/backtrace` users. -fn main() { +#[test] +fn slice_from_array() { let _ = <&[u8]>::from(&[]); } diff --git a/tests/ui/stdlib-unit-tests/volatile-fat-ptr.rs b/library/std/tests/volatile-fat-ptr.rs similarity index 90% rename from tests/ui/stdlib-unit-tests/volatile-fat-ptr.rs rename to library/std/tests/volatile-fat-ptr.rs index ef227a9134d..b005c12c618 100644 --- a/tests/ui/stdlib-unit-tests/volatile-fat-ptr.rs +++ b/library/std/tests/volatile-fat-ptr.rs @@ -1,10 +1,10 @@ -//@ run-pass - #![allow(stable_features)] #![feature(volatile)] + use std::ptr::{read_volatile, write_volatile}; -fn main() { +#[test] +fn volatile_fat_ptr() { let mut x: &'static str = "test"; unsafe { let a = read_volatile(&x);