mozilla / uniffi-rs

a multi-language bindings generator for rust
https://mozilla.github.io/uniffi-rs/
Mozilla Public License 2.0
2.77k stars 230 forks source link

Add support for test only functions #185

Open tarikeshaq opened 4 years ago

tarikeshaq commented 4 years ago

It's not urgent at all, since the consumer can create abstractions that hide certain functions but wanted to see what we think about this (Or if we just wanna say "leave it to the consumer to deal with it")

The idea is that there may be some functions that you want to expose for tests, but nothing else.

In Android you can do something like @VisibleForTesting(otherwise = VisibleForTesting.NONE)

I'm tempted towards the "leave it to the consumer to deal with" for the foreseeable future. But if we were to do this at some point, we can probably mark it with a WebIDL attribute similar to how errors are done in #31

┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-6

linabutler commented 4 years ago

This would be nifty to have!

Swift handles this a little differently—when you use @testable import to import a library, you get access to any internal (though not private or fileprivate) members and methods. For the Swift bindings, we could use the WebIDL attribute to keep the method internal instead of public.

jhugman commented 4 years ago

For android, this is implemented as androidx.annotation.VisibleForTesting, but the annotation processor is part of androidx, rather than kotlin itself. This will unlikely to be a problem for uniffi's consumers, but will make it hard for us to use outside of an android build process.