Skip to content

Commit 8cef37d

Browse files
committed
Auto merge of #124497 - rytheo:move-std-tests-to-library, r=workingjubilee
Move some stdlib tests from `tests/ui` to `library/std/tests` Related to #99417
2 parents 69f53f5 + 1bec124 commit 8cef37d

11 files changed

+97
-89
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ run-pass
21
// Test that `Clone` is correctly implemented for builtin types.
32
// Also test that cloning an array or a tuple is done right, i.e.
43
// each component is cloned.
@@ -7,7 +6,7 @@ fn test_clone<T: Clone>(arg: T) {
76
let _ = arg.clone();
87
}
98

10-
fn foo() { }
9+
fn foo() {}
1110

1211
#[derive(Debug, PartialEq, Eq)]
1312
struct S(i32);
@@ -18,7 +17,8 @@ impl Clone for S {
1817
}
1918
}
2019

21-
fn main() {
20+
#[test]
21+
fn builtin_clone() {
2222
test_clone(foo);
2323
test_clone([1; 56]);
2424
test_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1));
@@ -27,19 +27,7 @@ fn main() {
2727
let b = [S(1), S(2), S(3)];
2828
assert_eq!(b, a.clone());
2929

30-
let a = (
31-
(S(1), S(0)),
32-
(
33-
(S(0), S(0), S(1)),
34-
S(0)
35-
)
36-
);
37-
let b = (
38-
(S(2), S(1)),
39-
(
40-
(S(1), S(1), S(2)),
41-
S(1)
42-
)
43-
);
30+
let a = ((S(1), S(0)), ((S(0), S(0), S(1)), S(0)));
31+
let b = ((S(2), S(1)), ((S(1), S(1), S(2)), S(1)));
4432
assert_eq!(b, a.clone());
4533
}

Diff for: library/std/tests/eq-multidispatch.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#[derive(PartialEq, Debug)]
2+
struct Bar;
3+
#[derive(Debug)]
4+
struct Baz;
5+
#[derive(Debug)]
6+
struct Foo;
7+
#[derive(Debug)]
8+
struct Fu;
9+
10+
impl PartialEq for Baz {
11+
fn eq(&self, _: &Baz) -> bool {
12+
true
13+
}
14+
}
15+
16+
impl PartialEq<Fu> for Foo {
17+
fn eq(&self, _: &Fu) -> bool {
18+
true
19+
}
20+
}
21+
22+
impl PartialEq<Foo> for Fu {
23+
fn eq(&self, _: &Foo) -> bool {
24+
true
25+
}
26+
}
27+
28+
impl PartialEq<Bar> for Foo {
29+
fn eq(&self, _: &Bar) -> bool {
30+
false
31+
}
32+
}
33+
34+
impl PartialEq<Foo> for Bar {
35+
fn eq(&self, _: &Foo) -> bool {
36+
false
37+
}
38+
}
39+
40+
#[test]
41+
fn eq_multidispatch() {
42+
assert!(Bar != Foo);
43+
assert!(Foo != Bar);
44+
45+
assert_eq!(Bar, Bar);
46+
47+
assert_eq!(Baz, Baz);
48+
49+
assert_eq!(Foo, Fu);
50+
assert_eq!(Fu, Foo);
51+
}

Diff for: tests/ui/stdlib-unit-tests/istr.rs renamed to library/std/tests/istr.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//@ run-pass
2-
1+
#[test]
32
fn test_stack_assign() {
43
let s: String = "a".to_string();
54
println!("{}", s.clone());
@@ -9,8 +8,12 @@ fn test_stack_assign() {
98
assert!((s != u));
109
}
1110

12-
fn test_heap_lit() { "a big string".to_string(); }
11+
#[test]
12+
fn test_heap_lit() {
13+
"a big string".to_string();
14+
}
1315

16+
#[test]
1417
fn test_heap_assign() {
1518
let s: String = "a big ol' string".to_string();
1619
let t: String = "a big ol' string".to_string();
@@ -19,11 +22,13 @@ fn test_heap_assign() {
1922
assert!((s != u));
2023
}
2124

25+
#[test]
2226
fn test_heap_log() {
2327
let s = "a big ol' string".to_string();
2428
println!("{}", s);
2529
}
2630

31+
#[test]
2732
fn test_append() {
2833
let mut s = String::new();
2934
s.push_str("a");
@@ -41,11 +46,3 @@ fn test_append() {
4146
s.push_str("&tea");
4247
assert_eq!(s, "coffee&tea");
4348
}
44-
45-
pub fn main() {
46-
test_stack_assign();
47-
test_heap_lit();
48-
test_heap_assign();
49-
test_heap_log();
50-
test_append();
51-
}

Diff for: tests/ui/stdlib-unit-tests/log-knows-the-names-of-variants-in-std.rs renamed to library/std/tests/log-knows-the-names-of-variants-in-std.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
//@ run-pass
2-
31
#![allow(non_camel_case_types)]
42
#![allow(dead_code)]
3+
54
#[derive(Clone, Debug)]
65
enum foo {
7-
a(usize),
8-
b(String),
6+
a(usize),
7+
b(String),
98
}
109

1110
fn check_log<T: std::fmt::Debug>(exp: String, v: T) {
1211
assert_eq!(exp, format!("{:?}", v));
1312
}
1413

15-
pub fn main() {
14+
#[test]
15+
fn log_knows_the_names_of_variants_in_std() {
1616
let mut x = Some(foo::a(22));
1717
let exp = "Some(a(22))".to_string();
1818
let act = format!("{:?}", x);

Diff for: tests/ui/stdlib-unit-tests/minmax-stability-issue-23687.rs renamed to library/std/tests/minmax-stability-issue-23687.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
//@ run-pass
2-
3-
use std::fmt::Debug;
41
use std::cmp::{self, Ordering};
2+
use std::fmt::Debug;
53

64
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
75
struct Foo {
86
n: u8,
9-
name: &'static str
7+
name: &'static str,
108
}
119

1210
impl PartialOrd for Foo {
@@ -21,7 +19,8 @@ impl Ord for Foo {
2119
}
2220
}
2321

24-
fn main() {
22+
#[test]
23+
fn minmax_stability() {
2524
let a = Foo { n: 4, name: "a" };
2625
let b = Foo { n: 4, name: "b" };
2726
let c = Foo { n: 8, name: "c" };

Diff for: tests/ui/stdlib-unit-tests/seq-compare.rs renamed to library/std/tests/seq-compare.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
//@ run-pass
2-
3-
pub fn main() {
1+
#[test]
2+
fn seq_compare() {
43
assert!(("hello".to_string() < "hellr".to_string()));
54
assert!(("hello ".to_string() > "hello".to_string()));
65
assert!(("hello".to_string() != "there".to_string()));
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
//@ check-pass
2-
31
// This intends to use the unsizing coercion from array to slice, but it only
42
// works if we resolve `<&[u8]>::from` as the reflexive `From<T> for T`. In
53
// #113238, we found that gimli had added its own `From<EndianSlice> for &[u8]`
64
// that affected all `std/backtrace` users.
7-
fn main() {
5+
#[test]
6+
fn slice_from_array() {
87
let _ = <&[u8]>::from(&[]);
98
}

Diff for: tests/ui/stdlib-unit-tests/issue-21058.rs renamed to library/std/tests/type-name-unsized.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
//@ run-pass
21
#![allow(dead_code)]
32

43
use std::fmt::Debug;
54

65
struct NT(str);
7-
struct DST { a: u32, b: str }
6+
7+
struct DST {
8+
a: u32,
9+
b: str,
10+
}
811

912
macro_rules! check {
1013
(val: $ty_of:expr, $expected:expr) => {
@@ -15,23 +18,24 @@ macro_rules! check {
1518
};
1619
}
1720

18-
fn main() {
19-
// type_name should support unsized types
21+
/// Tests that [`std::any::type_name`] supports unsized types.
22+
#[test]
23+
fn type_name_unsized() {
2024
check!([u8], "[u8]");
2125
check!(str, "str");
2226
check!(dyn Send, "dyn core::marker::Send");
23-
check!(NT, "issue_21058::NT");
24-
check!(DST, "issue_21058::DST");
27+
check!(NT, "type_name_unsized::NT");
28+
check!(DST, "type_name_unsized::DST");
2529
check!(&i32, "&i32");
2630
check!(&'static i32, "&i32");
2731
check!((i32, u32), "(i32, u32)");
28-
check!(val: foo(), "issue_21058::Foo");
29-
check!(val: Foo::new, "issue_21058::Foo::new");
32+
check!(val: foo(), "type_name_unsized::Foo");
33+
check!(val: Foo::new, "type_name_unsized::Foo::new");
3034
check!(val:
3135
<Foo as Debug>::fmt,
32-
"<issue_21058::Foo as core::fmt::Debug>::fmt"
36+
"<type_name_unsized::Foo as core::fmt::Debug>::fmt"
3337
);
34-
check!(val: || {}, "issue_21058::main::{{closure}}");
38+
check!(val: || {}, "type_name_unsized::type_name_unsized::{{closure}}");
3539
bar::<i32>();
3640
}
3741

@@ -56,7 +60,9 @@ fn type_name_of_val<T>(_: T) -> &'static str {
5660
struct Foo;
5761

5862
impl Foo {
59-
fn new() -> Self { Foo }
63+
fn new() -> Self {
64+
Foo
65+
}
6066
}
6167

6268
fn foo() -> impl Debug {

Diff for: tests/ui/stdlib-unit-tests/volatile-fat-ptr.rs renamed to library/std/tests/volatile-fat-ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//@ run-pass
2-
31
#![allow(stable_features)]
42
#![feature(volatile)]
3+
54
use std::ptr::{read_volatile, write_volatile};
65

7-
fn main() {
6+
#[test]
7+
fn volatile_fat_ptr() {
88
let mut x: &'static str = "test";
99
unsafe {
1010
let a = read_volatile(&x);

Diff for: src/tools/tidy/src/issues.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3862,7 +3862,6 @@ ui/statics/issue-91050-1.rs
38623862
ui/statics/issue-91050-2.rs
38633863
ui/std/issue-3563-3.rs
38643864
ui/std/issue-81357-unsound-file-methods.rs
3865-
ui/stdlib-unit-tests/issue-21058.rs
38663865
ui/structs-enums/enum-rec/issue-17431-6.rs
38673866
ui/structs-enums/enum-rec/issue-17431-7.rs
38683867
ui/structs-enums/issue-103869.rs

Diff for: tests/ui/stdlib-unit-tests/eq-multidispatch.rs

-30
This file was deleted.

0 commit comments

Comments
 (0)