Skip to content

Commit f23c3fc

Browse files
authored
Merge pull request #35 from madsmtm/trybuild
Use `trybuild` for testing compilation failures
2 parents 141f25c + ddf483a commit f23c3fc

29 files changed

+470
-87
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ jobs:
4242
- name: Test macOS 10.15
4343
os: macos-10.15
4444
target: x86_64-apple-darwin
45-
- name: Test macOS 11
45+
- name: Test macOS 11 w. ui tests
4646
os: macos-11
4747
target: x86_64-apple-darwin
48+
args: --features tests/ui
4849
- name: Build macOS AArch64
4950
os: macos-11
5051
target: aarch64-apple-darwin
@@ -54,11 +55,12 @@ jobs:
5455
target: x86_64-apple-darwin
5556
# Oldest macOS version we support
5657
sdk: 10.7
57-
- name: Test macOS nightly
58+
- name: Test macOS nightly w. ui tests
5859
os: macos-latest
5960
target: x86_64-apple-darwin
6061
rust:
6162
toolchain: nightly
63+
args: --features tests/ui
6264
- name: Build macOS 32bit
6365
os: macos-10.15
6466
target: i686-apple-darwin

objc2-foundation/src/array.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ unsafe impl<T: Sync + Send> Send for NSArray<T, Shared> {}
4141
unsafe impl<T: Sync> Sync for NSArray<T, Owned> {}
4242
unsafe impl<T: Send> Send for NSArray<T, Owned> {}
4343

44-
/// ```compile_fail
45-
/// use objc2::rc::Shared;
46-
/// use objc2::runtime::Object;
47-
/// use objc2_foundation::NSArray;
48-
/// fn needs_send_sync<T: Send + Sync>() {}
49-
/// needs_send_sync::<NSArray<Object, Shared>>();
50-
/// ```
51-
#[cfg(doctest)]
52-
pub struct NSArrayWithObjectNotSendSync;
53-
5444
object! {
5545
// TODO: Ensure that this deref to NSArray is safe!
5646
unsafe pub struct NSMutableArray<T, O: Ownership>: NSArray<T, O> {

objc2-foundation/src/object.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ object! {
1010
unsafe pub struct NSObject: Object;
1111
}
1212

13-
/// ```compile_fail
14-
/// use objc2_foundation::NSObject;
15-
/// fn needs_sync<T: Sync>() {}
16-
/// needs_sync::<NSObject>();
17-
/// ```
18-
/// ```compile_fail
19-
/// use objc2_foundation::NSObject;
20-
/// fn needs_send<T: Send>() {}
21-
/// needs_send::<NSObject>();
22-
/// ```
23-
#[cfg(doctest)]
24-
pub struct NSObjectNotSendNorSync;
25-
2613
impl NSObject {
2714
unsafe_def_fn!(pub fn new -> Owned);
2815

objc2-foundation/src/string.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ impl NSString {
4343
}
4444

4545
/// TODO
46-
///
47-
/// ```compile_fail
48-
/// # use objc2::rc::autoreleasepool;
49-
/// # use objc2_foundation::NSString;
50-
/// autoreleasepool(|pool| {
51-
/// let ns_string = NSString::new();
52-
/// let s = ns_string.as_str(pool);
53-
/// drop(ns_string);
54-
/// println!("{}", s);
55-
/// });
56-
/// ```
57-
///
58-
/// ```compile_fail
59-
/// # use objc2::rc::autoreleasepool;
60-
/// # use objc2_foundation::NSString;
61-
/// let ns_string = NSString::new();
62-
/// let s = autoreleasepool(|pool| ns_string.as_str(pool));
63-
/// ```
6446
pub fn as_str<'r, 's: 'r, 'p: 'r>(&'s self, pool: &'p AutoreleasePool) -> &'r str {
6547
// This is necessary until `auto` types stabilizes.
6648
pool.__verify_is_inner();

objc2-foundation/src/value.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,6 @@ impl<T: 'static + Copy + Encode + fmt::Display> fmt::Display for NSValue<T> {
110110
}
111111
}
112112

113-
/// ```compile_fail
114-
/// use objc2_foundation::NSValue;
115-
/// fn needs_eq<T: Eq>() {}
116-
/// needs_eq::<NSValue<f32>>();
117-
/// ```
118-
#[cfg(doctest)]
119-
pub struct NSValueFloatNotEq;
120-
121113
#[cfg(test)]
122114
mod tests {
123115
use alloc::format;

objc2/src/rc/autorelease.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,6 @@ pub struct AutoreleasePool {
2525
p: PhantomData<*mut UnsafeCell<c_void>>,
2626
}
2727

28-
/// ```
29-
/// use objc2::rc::AutoreleasePool;
30-
/// fn needs_nothing<T>() {}
31-
/// needs_nothing::<AutoreleasePool>();
32-
/// ```
33-
/// ```compile_fail
34-
/// use objc2::rc::AutoreleasePool;
35-
/// fn needs_sync<T: Sync>() {}
36-
/// needs_sync::<AutoreleasePool>();
37-
/// ```
38-
/// ```compile_fail
39-
/// use objc2::rc::AutoreleasePool;
40-
/// fn needs_send<T: Send>() {}
41-
/// needs_send::<AutoreleasePool>();
42-
/// ```
43-
#[cfg(doctest)]
44-
pub struct AutoreleasePoolNotSendNorSync;
45-
4628
#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
4729
thread_local! {
4830
/// We track the thread's pools to verify that object lifetimes are only

objc2/src/runtime.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -613,24 +613,6 @@ impl Object {
613613
// objc_removeAssociatedObjects
614614
}
615615

616-
/// ```
617-
/// use objc2::runtime::Object;
618-
/// fn needs_nothing<T: ?Sized>() {}
619-
/// needs_nothing::<Object>();
620-
/// ```
621-
/// ```compile_fail
622-
/// use objc2::runtime::Object;
623-
/// fn needs_sync<T: ?Sized + Sync>() {}
624-
/// needs_sync::<Object>();
625-
/// ```
626-
/// ```compile_fail
627-
/// use objc2::runtime::Object;
628-
/// fn needs_send<T: ?Sized + Send>() {}
629-
/// needs_send::<Object>();
630-
/// ```
631-
#[cfg(doctest)]
632-
pub struct ObjectNotSendNorSync;
633-
634616
unsafe impl RefEncode for Object {
635617
const ENCODING_REF: Encoding<'static> = Encoding::Object;
636618
}

tests/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@ license = "MIT"
99

1010
build = "build.rs"
1111

12+
[features]
13+
# Enable UI tests
14+
#
15+
# These are not enabled by default because trybuild doesn't pass feature flags
16+
# (like --features gnustep-1-9) to its cargo invocation, and hence they don't
17+
# always work.
18+
#
19+
# Also, they're slower than most tests.
20+
ui = ["trybuild"]
21+
1222
[dependencies]
1323
block2 = { path = "../block2" }
1424
block-sys = { path = "../block-sys" }
1525
objc-sys = { path = "../objc-sys" }
1626
objc2 = { path = "../objc2" }
1727
objc2-encode = { path = "../objc2-encode" }
28+
objc2-foundation = { path = "../objc2-foundation" }
29+
30+
# Put here instead of dev-dependencies because we want to make it optional
31+
trybuild = { version = "1.0", optional = true }
1832

1933
[build-dependencies]
2034
cc = "1.0"

tests/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,11 @@ mod tests {
140140
let block = block.copy();
141141
assert_eq!(invoke_large_struct_block(&block, data), new_data);
142142
}
143+
144+
#[test]
145+
#[cfg(feature = "ui")]
146+
fn ui() {
147+
let t = trybuild::TestCases::new();
148+
t.compile_fail("ui/*.rs");
149+
}
143150
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Test that AutoreleasePool is not Send and Sync, because it internally
2+
//! works with thread locals.
3+
4+
use objc2::rc::AutoreleasePool;
5+
6+
fn needs_sync<T: ?Sized + Sync>() {}
7+
fn needs_send<T: ?Sized + Send>() {}
8+
9+
fn main() {
10+
needs_sync::<AutoreleasePool>();
11+
needs_send::<AutoreleasePool>();
12+
}

0 commit comments

Comments
 (0)