-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable nullability for public api #856
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2fc9241
Adopt records for some classes
Romfos b990b77
Obsolete Arg.Compat
Romfos 1a1f964
Enable nullability for public api
Romfos 9d46068
Update changelogs
Romfos 94b64cb
Disable compat warnings for ArgumentMatchingCompat
Romfos 28bd6b6
Remove unsuable files
Romfos 7f63a73
Update changelog
Romfos 382ccc3
Added workaraund for nullability
Romfos 922e883
Update editorconfig
Romfos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System.Linq.Expressions; | ||
|
||
// Disable nullability for client API, so it does not affect clients. | ||
#nullable disable annotations | ||
#pragma warning disable CS0419 | ||
|
||
namespace NSubstitute; | ||
|
||
public static partial class Arg | ||
{ | ||
/// <summary> | ||
/// Alternate version of <see cref="Arg"/> matchers for compatibility with pre-C#7 compilers | ||
/// which do not support <c>ref</c> return types. Do not use unless you are unable to use <see cref="Arg"/>. | ||
/// | ||
/// For more information see <see href="https://nsubstitute.github.io/help/compat-args">Compatibility Argument | ||
/// Matchers</see> in the NSubstitute documentation. | ||
/// </summary> | ||
[Obsolete("This api is deprecated and will be removed in future versions of product.")] | ||
public static class Compat | ||
{ | ||
/// <summary> | ||
/// Match any argument value compatible with type <typeparamref name="T"/>. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Any{T}" /> instead. | ||
/// </summary> | ||
public static T Any<T>() => Arg.Any<T>(); | ||
|
||
/// <summary> | ||
/// Match argument that is equal to <paramref name="value"/>. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Is{T}(T)" /> instead. | ||
/// </summary> | ||
public static T Is<T>(T value) => Arg.Is(value); | ||
|
||
/// <summary> | ||
/// Match argument that satisfies <paramref name="predicate"/>. | ||
/// If the <paramref name="predicate"/> throws an exception for an argument it will be treated as non-matching. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Is{T}(Expression{Predicate{T}})" /> instead. | ||
/// </summary> | ||
public static T Is<T>(Expression<Predicate<T>> predicate) => Arg.Is(predicate); | ||
|
||
/// <summary> | ||
/// Match argument that satisfies <paramref name="predicate"/>. | ||
/// If the <paramref name="predicate"/> throws an exception for an argument it will be treated as non-matching. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Is{T}(Expression{Predicate{T}})" /> instead. | ||
/// </summary> | ||
public static AnyType Is<T>(Expression<Predicate<object>> predicate) where T : AnyType => Arg.Is<T>(predicate); | ||
|
||
/// <summary> | ||
/// Invoke any <see cref="Action"/> argument whenever a matching call is made to the substitute. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Invoke" /> instead. | ||
/// </summary> | ||
public static Action Invoke() => Arg.Invoke(); | ||
|
||
/// <summary> | ||
/// Invoke any <see cref="Action<T>"/> argument with specified argument whenever a matching call is made to the substitute. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Invoke{T}" /> instead. | ||
/// </summary> | ||
public static Action<T> Invoke<T>(T arg) => Arg.Invoke(arg); | ||
|
||
/// <summary> | ||
/// Invoke any <see cref="Action<T1,T2>"/> argument with specified arguments whenever a matching call is made to the substitute. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Invoke{T1,T2}" /> instead. | ||
/// </summary> | ||
public static Action<T1, T2> Invoke<T1, T2>(T1 arg1, T2 arg2) => Arg.Invoke(arg1, arg2); | ||
|
||
/// <summary> | ||
/// Invoke any <see cref="Action<T1,T2,T3>"/> argument with specified arguments whenever a matching call is made to the substitute. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Invoke{T1,T2,T3}" /> instead. | ||
/// </summary> | ||
public static Action<T1, T2, T3> Invoke<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3) => Arg.Invoke(arg1, arg2, arg3); | ||
|
||
/// <summary> | ||
/// Invoke any <see cref="Action<T1,T2,T3,T4>"/> argument with specified arguments whenever a matching call is made to the substitute. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Invoke{T1,T2,T3,T4}" /> instead. | ||
/// </summary> | ||
public static Action<T1, T2, T3, T4> Invoke<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4) => Arg.Invoke(arg1, arg2, arg3, arg4); | ||
|
||
/// <summary> | ||
/// Invoke any <typeparamref name="TDelegate"/> argument with specified arguments whenever a matching call is made to the substitute. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.InvokeDelegate{TDelegate}" /> instead. | ||
/// </summary> | ||
/// <param name="arguments">Arguments to pass to delegate.</param> | ||
public static TDelegate InvokeDelegate<TDelegate>(params object[] arguments) => Arg.InvokeDelegate<TDelegate>(arguments); | ||
|
||
/// <summary> | ||
/// Capture any argument compatible with type <typeparamref name="T"/> and use it to call the <paramref name="useArgument"/> function | ||
/// whenever a matching call is made to the substitute. | ||
/// This is provided for compatibility with older compilers -- | ||
/// if possible use <see cref="Arg.Do{T}" /> instead. | ||
/// </summary> | ||
public static T Do<T>(Action<T> useArgument) => Arg.Do<T>(useArgument); | ||
|
||
/// <summary> | ||
/// Capture any argument compatible with type <typeparamref name="T"/> and use it to call the <paramref name="useArgument"/> function | ||
/// whenever a matching call is made to the substitute. | ||
/// </summary> | ||
public static AnyType Do<T>(Action<object> useArgument) where T : AnyType => Arg.Do<T>(useArgument); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that it's a bit too late to jump into the train, as it was merged, but I find this change a bit questionable and am concerned about usability of it. For example here now
T
is nullable, but that's not the case at all. It depends solely on the method we invoke whether the value isnull
or not. I understand that we don't have a chance to infer that somehow - but yet now people will be forced to use null-forgiving operator. That isn't convenient at all. It's like.ToString()!
you have to write all the time - it's annoying and it frankly sucks 😟The primary purpose of this library is to enable unit testing. I would find it quite surprising that people would have nullability enabled in the unit tests, as.. well, it's unit tests, not the production code and you want to have flexibility there. I could totally see that some are enabling, but yet I wouldn't imagine it being the default.
My primary argument is that we cannot promise nullability or describe anything meaningful - shall we just not enable it for classes like
Arg
? Like if you don't know the answer to the question - you just say "I don't know" instead of pretending you know something. After this change the compilation could break for the existing test projects (if they have the nullability enabled) and people will have to go and manually suppress it everywhere - isn't it annoying?@Romfos @dtchepak What are you thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zvirja Thanks for the thoughts. I haven't used C# since nullability changes (mainly Kotlin at the moment), so not across this. This hasn't made it to release so it's fine to revert.