Skip to content

Commit

Permalink
Don't require AppKit in UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Dec 3, 2023
1 parent 8e3ff12 commit 611e5f1
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 78 deletions.
2 changes: 0 additions & 2 deletions crates/test-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ default = [
"icrate/Foundation_NSMutableArray",
"icrate/Foundation_NSValue",
"icrate/Foundation_NSSet",
"icrate/AppKit",
"icrate/AppKit_NSApplication",
"objc2/unstable-msg-send-always-comma",
]
std = ["block2/std", "objc2/std", "icrate/std"]
Expand Down
30 changes: 19 additions & 11 deletions crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
//! Test that implementing `NSApplicationDelegate` and similar requires
//! a `MainThreadOnly` class.
use icrate::AppKit::{NSApplication, NSApplicationDelegate};
use icrate::Foundation::{MainThreadMarker, NSNotification, NSObject, NSObjectProtocol};
use objc2::mutability::IsMainThreadOnly;
use objc2::rc::Id;
use objc2::runtime::ProtocolObject;
use objc2::{declare_class, extern_methods, mutability, ClassType, DeclaredClass};
use objc2::{
declare_class, extern_methods, extern_protocol, mutability, ClassType, DeclaredClass,
ProtocolType,
};

// Use fake `NSApplicationDelegate` so that this works on iOS too.
extern_protocol!(
pub unsafe trait NSApplicationDelegate: NSObjectProtocol + IsMainThreadOnly {
#[optional]
#[method(applicationDidFinishLaunching:)]
unsafe fn applicationDidFinishLaunching(&self, notification: &NSNotification);

// snip
}

unsafe impl ProtocolType for dyn NSApplicationDelegate {}
);

declare_class!(
struct CustomObject;
Expand Down Expand Up @@ -35,11 +50,4 @@ extern_methods!(
}
);

fn main() {
let mtm = MainThreadMarker::new().unwrap();
let app = NSApplication::sharedApplication(mtm);

let delegate = CustomObject::new(mtm);
let delegate = ProtocolObject::from_ref(&*delegate);
app.setDelegate(Some(delegate));
}
fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsMainThre
= help: the trait `mutability::MutabilityIsMainThreadOnly` is implemented for `MainThreadOnly`
= note: required for `CustomObject` to implement `IsMainThreadOnly`
note: required by a bound in `NSApplicationDelegate`
--> $WORKSPACE/crates/icrate/src/generated/AppKit/NSApplication.rs
--> ui/declare_class_delegate_not_mainthreadonly.rs
|
| / extern_protocol!(
| | pub unsafe trait NSApplicationDelegate: NSObjectProtocol + IsMainThreadOnly {
| | --------------------- required by a bound in this trait
| | #[cfg(feature = "AppKit_NSApplication")]
| | #[optional]
| | #[method(applicationDidFinishLaunching:)]
... |
| | unsafe impl ProtocolType for dyn NSApplicationDelegate {}
| | );
Expand Down
9 changes: 4 additions & 5 deletions crates/test-ui/ui/implement_protocol_missing_super.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Test that implementing traits like `NSApplicationDelegate` requires super
//! protocols like `NSObjectProtocol` to also be implemented.
use icrate::AppKit::NSApplicationDelegate;
use icrate::Foundation::NSObject;
//! Test that implementing certain traits like `NSURLSessionDelegate` requires
//! super protocols like `NSObjectProtocol` to also be implemented.
use icrate::Foundation::{NSObject, NSURLSessionDelegate};
use objc2::{declare_class, mutability, ClassType, DeclaredClass};

declare_class!(
Expand All @@ -15,7 +14,7 @@ declare_class!(

impl DeclaredClass for CustomObject {}

unsafe impl NSApplicationDelegate for CustomObject {}
unsafe impl NSURLSessionDelegate for CustomObject {}
);

fn main() {}
28 changes: 14 additions & 14 deletions crates/test-ui/ui/implement_protocol_missing_super.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error[E0277]: the trait bound `CustomObject: NSObjectProtocol` is not satisfied
--> ui/implement_protocol_missing_super.rs
|
| unsafe impl NSApplicationDelegate for CustomObject {}
| ^^^^^^^^^^^^ the trait `NSObjectProtocol` is not implemented for `CustomObject`
| unsafe impl NSURLSessionDelegate for CustomObject {}
| ^^^^^^^^^^^^ the trait `NSObjectProtocol` is not implemented for `CustomObject`
|
= help: the following other types implement trait `NSObjectProtocol`:
NSObject
__NSProxy
ProtocolObject<T>
NSApplication
NSCollectionView
NSCollectionLayoutSection
NSCollectionLayoutGroupCustomItem
NSControl
NSArray<ObjectType>
NSMutableArray<ObjectType>
NSDictionary<KeyType, ObjectType>
NSSet<ObjectType>
NSEnumerator<ObjectType>
and $N others
note: required by a bound in `NSApplicationDelegate`
--> $WORKSPACE/crates/icrate/src/generated/AppKit/NSApplication.rs
note: required by a bound in `NSURLSessionDelegate`
--> $WORKSPACE/crates/icrate/src/generated/Foundation/NSURLSession.rs
|
| / extern_protocol!(
| | pub unsafe trait NSApplicationDelegate: NSObjectProtocol + IsMainThreadOnly {
| | --------------------- required by a bound in this trait
| | #[cfg(feature = "AppKit_NSApplication")]
| | pub unsafe trait NSURLSessionDelegate: NSObjectProtocol {
| | -------------------- required by a bound in this trait
| | #[cfg(all(feature = "Foundation_NSError", feature = "Foundation_NSURLSession"))]
| | #[optional]
... |
| | unsafe impl ProtocolType for dyn NSApplicationDelegate {}
| | unsafe impl ProtocolType for dyn NSURLSessionDelegate {}
| | );
| |_^ required by this bound in `NSApplicationDelegate`
| |_^ required by this bound in `NSURLSessionDelegate`
= note: this error originates in the macro `extern_protocol` (in Nightly builds, run with -Z macro-backtrace for more info)
4 changes: 2 additions & 2 deletions crates/test-ui/ui/msg_send_invalid_error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ error[E0277]: the trait bound `i32: Message` is not satisfied
__NSProxy
ProtocolObject<P>
AnyObject
NSArray<ObjectType>
NSMutableArray<ObjectType>
__RcTestObject
NSApplication
NSCollectionView
and $N others
note: required by a bound in `send_message_error`
--> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs
Expand Down
14 changes: 7 additions & 7 deletions crates/test-ui/ui/nsarray_not_message.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ error[E0277]: the trait bound `i32: Message` is not satisfied
__NSProxy
ProtocolObject<P>
AnyObject
NSArray<ObjectType>
NSMutableArray<ObjectType>
__RcTestObject
NSApplication
NSCollectionView
and $N others
note: required by a bound in `Foundation::__NSArray::<impl NSArray<ObjectType>>::new`
--> $WORKSPACE/crates/icrate/src/generated/Foundation/NSArray.rs
Expand Down Expand Up @@ -40,12 +40,12 @@ error[E0277]: the trait bound `Id<NSObject>: ClassType` is not satisfied
= help: the following other types implement trait `ClassType`:
NSObject
__NSProxy
NSArray<ObjectType>
NSMutableArray<ObjectType>
__RcTestObject
NSApplication
NSCollectionView
NSCollectionLayoutSection
NSCollectionLayoutGroupCustomItem
NSControl
NSDictionary<KeyType, ObjectType>
NSMutableDictionary<KeyType, ObjectType>
NSSet<ObjectType>
and $N others
= note: required for `Id<NSObject>` to implement `IsRetainable`
note: required by a bound in `icrate::Foundation::array::<impl NSArray<T>>::from_slice`
Expand Down
70 changes: 35 additions & 35 deletions crates/test-ui/ui/protocol_object_only_protocols.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ error[E0277]: the trait bound `NSObject: ImplementedBy<NSObject>` is not satisfi
(dyn NSObjectProtocol + Send + 'static)
(dyn NSObjectProtocol + Sync + 'static)
(dyn NSObjectProtocol + Send + Sync + 'static)
(dyn NSAccessibilityColor + 'static)
(dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static)
(dyn NSAccessibilityElementProtocol + 'static)
(dyn NSAccessibilityGroup + 'static)
(dyn NSCopying + 'static)
(dyn NSMutableCopying + 'static)
(dyn NSCacheDelegate + 'static)
(dyn NSConnectionDelegate + 'static)
and $N others
note: required by a bound in `ProtocolObject::<P>::from_ref`
--> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs
Expand All @@ -38,10 +38,10 @@ error[E0277]: the trait bound `dyn Send: ImplementedBy<NSObject>` is not satisfi
(dyn NSObjectProtocol + Send + 'static)
(dyn NSObjectProtocol + Sync + 'static)
(dyn NSObjectProtocol + Send + Sync + 'static)
(dyn NSAccessibilityColor + 'static)
(dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static)
(dyn NSAccessibilityElementProtocol + 'static)
(dyn NSAccessibilityGroup + 'static)
(dyn NSCopying + 'static)
(dyn NSMutableCopying + 'static)
(dyn NSCacheDelegate + 'static)
(dyn NSConnectionDelegate + 'static)
and $N others
note: required by a bound in `ProtocolObject::<P>::from_ref`
--> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs
Expand All @@ -65,10 +65,10 @@ error[E0277]: the trait bound `dyn Foo: ImplementedBy<NSObject>` is not satisfie
(dyn NSObjectProtocol + Send + 'static)
(dyn NSObjectProtocol + Sync + 'static)
(dyn NSObjectProtocol + Send + Sync + 'static)
(dyn NSAccessibilityColor + 'static)
(dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static)
(dyn NSAccessibilityElementProtocol + 'static)
(dyn NSAccessibilityGroup + 'static)
(dyn NSCopying + 'static)
(dyn NSMutableCopying + 'static)
(dyn NSCacheDelegate + 'static)
(dyn NSConnectionDelegate + 'static)
and $N others
note: required by a bound in `ProtocolObject::<P>::from_ref`
--> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs
Expand All @@ -93,10 +93,10 @@ error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely
(dyn NSObjectProtocol + Send + 'static)
(dyn NSObjectProtocol + Sync + 'static)
(dyn NSObjectProtocol + Send + Sync + 'static)
(dyn NSAccessibilityColor + 'static)
(dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static)
(dyn NSAccessibilityElementProtocol + 'static)
(dyn NSAccessibilityGroup + 'static)
(dyn NSCopying + 'static)
(dyn NSMutableCopying + 'static)
(dyn NSCacheDelegate + 'static)
(dyn NSConnectionDelegate + 'static)
and $N others
= note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)`
note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>`
Expand Down Expand Up @@ -148,10 +148,10 @@ error[E0277]: `UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>`
(dyn NSObjectProtocol + Send + 'static)
(dyn NSObjectProtocol + Sync + 'static)
(dyn NSObjectProtocol + Send + Sync + 'static)
(dyn NSAccessibilityColor + 'static)
(dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static)
(dyn NSAccessibilityElementProtocol + 'static)
(dyn NSAccessibilityGroup + 'static)
(dyn NSCopying + 'static)
(dyn NSMutableCopying + 'static)
(dyn NSCacheDelegate + 'static)
(dyn NSConnectionDelegate + 'static)
and $N others
note: required because it appears within the type `objc_object`
--> $WORKSPACE/crates/objc-sys/src/object.rs
Expand Down Expand Up @@ -192,10 +192,10 @@ error[E0277]: `UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>`
(dyn NSObjectProtocol + Send + 'static)
(dyn NSObjectProtocol + Sync + 'static)
(dyn NSObjectProtocol + Send + Sync + 'static)
(dyn NSAccessibilityColor + 'static)
(dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static)
(dyn NSAccessibilityElementProtocol + 'static)
(dyn NSAccessibilityGroup + 'static)
(dyn NSCopying + 'static)
(dyn NSMutableCopying + 'static)
(dyn NSCacheDelegate + 'static)
(dyn NSConnectionDelegate + 'static)
and $N others
note: required because it appears within the type `objc_object`
--> $WORKSPACE/crates/objc-sys/src/object.rs
Expand Down Expand Up @@ -236,10 +236,10 @@ error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely
(dyn NSObjectProtocol + Send + 'static)
(dyn NSObjectProtocol + Sync + 'static)
(dyn NSObjectProtocol + Send + Sync + 'static)
(dyn NSAccessibilityColor + 'static)
(dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static)
(dyn NSAccessibilityElementProtocol + 'static)
(dyn NSAccessibilityGroup + 'static)
(dyn NSCopying + 'static)
(dyn NSMutableCopying + 'static)
(dyn NSCacheDelegate + 'static)
(dyn NSConnectionDelegate + 'static)
and $N others
= note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)`
note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>`
Expand Down Expand Up @@ -287,13 +287,13 @@ error[E0277]: the trait bound `NSObject: NSCopying` is not satisfied
|
= help: the following other types implement trait `NSCopying`:
ProtocolObject<T>
__RcTestObject
NSCollectionLayoutSection
NSCollectionLayoutGroupCustomItem
NSArray<ObjectType>
NSMutableArray<ObjectType>
__RcTestObject
NSDictionary<KeyType, ObjectType>
NSSet<ObjectType>
NSAppleEventDescriptor
NSError
and $N others
= note: required for `dyn NSCopying` to implement `ImplementedBy<NSObject>`
note: required by a bound in `ProtocolObject::<P>::from_ref`
Expand All @@ -318,10 +318,10 @@ error[E0277]: the trait bound `dyn NSCopying + Send: ImplementedBy<NSObject>` is
(dyn NSObjectProtocol + Send + 'static)
(dyn NSObjectProtocol + Sync + 'static)
(dyn NSObjectProtocol + Send + Sync + 'static)
(dyn NSAccessibilityColor + 'static)
(dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static)
(dyn NSAccessibilityElementProtocol + 'static)
(dyn NSAccessibilityGroup + 'static)
(dyn NSCopying + 'static)
(dyn NSMutableCopying + 'static)
(dyn NSCacheDelegate + 'static)
(dyn NSConnectionDelegate + 'static)
and $N others
note: required by a bound in `ProtocolObject::<P>::from_ref`
--> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs
Expand Down

0 comments on commit 611e5f1

Please sign in to comment.