1
Fork 0

Move various stdlib tests to library/std/tests

This commit is contained in:
Ryan Lowe 2024-04-28 15:37:14 -04:00
parent ce609db948
commit ed9d6e0c03
9 changed files with 24 additions and 33 deletions

View file

@ -1,4 +1,3 @@
//@ run-pass
// Test that `Clone` is correctly implemented for builtin types. // Test that `Clone` is correctly implemented for builtin types.
// Also test that cloning an array or a tuple is done right, i.e. // Also test that cloning an array or a tuple is done right, i.e.
// each component is cloned. // each component is cloned.
@ -18,7 +17,8 @@ impl Clone for S {
} }
} }
fn main() { #[test]
fn builtin_clone() {
test_clone(foo); test_clone(foo);
test_clone([1; 56]); test_clone([1; 56]);
test_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)); test_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1));

View file

@ -1,5 +1,3 @@
//@ run-pass
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
struct Bar; struct Bar;
#[derive(Debug)] #[derive(Debug)]
@ -17,7 +15,8 @@ impl PartialEq<Foo> for Fu { fn eq(&self, _: &Foo) -> bool { true } }
impl PartialEq<Bar> for Foo { fn eq(&self, _: &Bar) -> bool { false } } impl PartialEq<Bar> for Foo { fn eq(&self, _: &Bar) -> bool { false } }
impl PartialEq<Foo> for Bar { fn eq(&self, _: &Foo) -> bool { false } } impl PartialEq<Foo> for Bar { fn eq(&self, _: &Foo) -> bool { false } }
fn main() { #[test]
fn eq_multidispatch() {
assert!(Bar != Foo); assert!(Bar != Foo);
assert!(Foo != Bar); assert!(Foo != Bar);

View file

@ -1,4 +1,3 @@
//@ run-pass
#![allow(dead_code)] #![allow(dead_code)]
use std::fmt::Debug; use std::fmt::Debug;
@ -15,7 +14,8 @@ macro_rules! check {
}; };
} }
fn main() { #[test]
fn issue_21058() {
// type_name should support unsized types // type_name should support unsized types
check!([u8], "[u8]"); check!([u8], "[u8]");
check!(str, "str"); check!(str, "str");
@ -31,7 +31,7 @@ fn main() {
<Foo as Debug>::fmt, <Foo as Debug>::fmt,
"<issue_21058::Foo as core::fmt::Debug>::fmt" "<issue_21058::Foo as core::fmt::Debug>::fmt"
); );
check!(val: || {}, "issue_21058::main::{{closure}}"); check!(val: || {}, "issue_21058::issue_21058::{{closure}}");
bar::<i32>(); bar::<i32>();
} }

View file

@ -1,5 +1,4 @@
//@ run-pass #[test]
fn test_stack_assign() { fn test_stack_assign() {
let s: String = "a".to_string(); let s: String = "a".to_string();
println!("{}", s.clone()); println!("{}", s.clone());
@ -9,8 +8,10 @@ fn test_stack_assign() {
assert!((s != u)); assert!((s != u));
} }
#[test]
fn test_heap_lit() { "a big string".to_string(); } fn test_heap_lit() { "a big string".to_string(); }
#[test]
fn test_heap_assign() { fn test_heap_assign() {
let s: String = "a big ol' string".to_string(); let s: String = "a big ol' string".to_string();
let t: 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)); assert!((s != u));
} }
#[test]
fn test_heap_log() { fn test_heap_log() {
let s = "a big ol' string".to_string(); let s = "a big ol' string".to_string();
println!("{}", s); println!("{}", s);
} }
#[test]
fn test_append() { fn test_append() {
let mut s = String::new(); let mut s = String::new();
s.push_str("a"); s.push_str("a");
@ -41,11 +44,3 @@ fn test_append() {
s.push_str("&tea"); s.push_str("&tea");
assert_eq!(s, "coffee&tea"); assert_eq!(s, "coffee&tea");
} }
pub fn main() {
test_stack_assign();
test_heap_lit();
test_heap_assign();
test_heap_log();
test_append();
}

View file

@ -1,7 +1,6 @@
//@ run-pass
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![allow(dead_code)] #![allow(dead_code)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
enum foo { enum foo {
a(usize), a(usize),
@ -12,7 +11,8 @@ fn check_log<T: std::fmt::Debug>(exp: String, v: T) {
assert_eq!(exp, format!("{:?}", v)); 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 mut x = Some(foo::a(22));
let exp = "Some(a(22))".to_string(); let exp = "Some(a(22))".to_string();
let act = format!("{:?}", x); let act = format!("{:?}", x);

View file

@ -1,5 +1,3 @@
//@ run-pass
use std::fmt::Debug; use std::fmt::Debug;
use std::cmp::{self, Ordering}; use std::cmp::{self, Ordering};
@ -21,7 +19,8 @@ impl Ord for Foo {
} }
} }
fn main() { #[test]
fn minmax_stability() {
let a = Foo { n: 4, name: "a" }; let a = Foo { n: 4, name: "a" };
let b = Foo { n: 4, name: "b" }; let b = Foo { n: 4, name: "b" };
let c = Foo { n: 8, name: "c" }; let c = Foo { n: 8, name: "c" };

View file

@ -1,6 +1,5 @@
//@ run-pass #[test]
fn seq_compare() {
pub fn main() {
assert!(("hello".to_string() < "hellr".to_string())); assert!(("hello".to_string() < "hellr".to_string()));
assert!(("hello ".to_string() > "hello".to_string())); assert!(("hello ".to_string() > "hello".to_string()));
assert!(("hello".to_string() != "there".to_string())); assert!(("hello".to_string() != "there".to_string()));

View file

@ -1,9 +1,8 @@
//@ check-pass
// This intends to use the unsizing coercion from array to slice, but it only // This intends to use the unsizing coercion from array to slice, but it only
// works if we resolve `<&[u8]>::from` as the reflexive `From<T> for T`. In // works if we resolve `<&[u8]>::from` as the reflexive `From<T> for T`. In
// #113238, we found that gimli had added its own `From<EndianSlice> for &[u8]` // #113238, we found that gimli had added its own `From<EndianSlice> for &[u8]`
// that affected all `std/backtrace` users. // that affected all `std/backtrace` users.
fn main() { #[test]
fn slice_from_array() {
let _ = <&[u8]>::from(&[]); let _ = <&[u8]>::from(&[]);
} }

View file

@ -1,10 +1,10 @@
//@ run-pass
#![allow(stable_features)] #![allow(stable_features)]
#![feature(volatile)] #![feature(volatile)]
use std::ptr::{read_volatile, write_volatile}; use std::ptr::{read_volatile, write_volatile};
fn main() { #[test]
fn volatile_fat_ptr() {
let mut x: &'static str = "test"; let mut x: &'static str = "test";
unsafe { unsafe {
let a = read_volatile(&x); let a = read_volatile(&x);