Skip to content

Ensure lack of optional parameters #1031

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

Merged
merged 20 commits into from
May 15, 2015
Merged

Ensure lack of optional parameters #1031

merged 20 commits into from
May 15, 2015

Conversation

nulltoken
Copy link
Member

Fix #952

  • Create a MetaFixture ensuring no optional parameter is used
  • See the test fail
  • 🔥 the optionals
  • See the test pass

@shiftkey
Copy link
Contributor

😍 😍 😍 😍 😍

@nulltoken did you want an extra pair of hands to help with cleaning this up? otherwise I'm happy to help with reviewing...


foreach (var method in mis.Distinct())
{
sb.AppendFormat("At least one overload of method '{0}' accepts an optional paramater.{1}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: parameter

@nulltoken
Copy link
Member Author

@shiftkey Any help is welcome killing those optional parameters! 🙏

@shiftkey
Copy link
Contributor

@nulltoken I'll start from the bottom of the list then. Shall I PR into this PR, or just add commits directly?

@nulltoken
Copy link
Member Author

@shiftkey Please push directly on top of this branch. ❤️ for the help

from t in Assembly.GetAssembly(typeof(IRepository))
.GetExportedTypes()
from m in t.GetMethods()
where !m.IsObsolete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a couple of methods which have optional parameters but are marked as obsolete. I figure we don't care about migrating those. Let me know if that's not the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! They'll be dropped before stabilization (post v0.22)

/// <param name="xdgConfigurationFileLocation">Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed.</param>
/// <param name="systemConfigurationFileLocation">Path to a System configuration file. If null, the default path for a system configuration file will be probed.</param>
public Configuration(string globalConfigurationFileLocation = null, string xdgConfigurationFileLocation = null, string systemConfigurationFileLocation = null)
public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation, string systemConfigurationFileLocation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we wanted to overload everything here - I just went with the overloads for global and global/xdg. Would love some guidance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How you did it makes sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@shiftkey
Copy link
Contributor

Pausing here because I'm concerned about wrestling with the mocks for Configuration and Doing It Wrong™ - the new tests however are passing, and I Have Questions™ about the ctor overloads for Configuration.

@jamill
Copy link
Member

jamill commented Apr 28, 2015

😍

@shiftkey
Copy link
Contributor

@nulltoken thoughts on what I'm doing wrong with that leaked ConfigurationSafeHandle - I can't seem to trigger this when running the CanFakeEnumerationOfConfiguration test locally?

@jamill
Copy link
Member

jamill commented May 1, 2015

@shiftkey see this line - In order to trigger this, you need to have LEAKS_IDENTIFYING defined. uncomment that line, or add that symbol. Here is the trace with LEAKS_TRACKING specified:

at LibGit2Sharp.Core.NativeMethods.git_config_new(ConfigurationSafeHandle& cfg)
at LibGit2Sharp.Core.Proxy.git_config_new() in C:\Users\jamill\gitWorkspaces\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 482
at LibGit2Sharp.Configuration.Init() in C:\Users\jamill\gitWorkspaces\libgit2sharp\LibGit2Sharp\Configuration.cs:line 46
at LibGit2Sharp.Configuration..ctor(Repository repository, String globalConfigurationFileLocation, String xdgConfigurationFileLocation, String systemConfigurationFileLocation) in C:\Users\jamill\gitWorkspaces\libgit2sharp\LibGit2Sharp\Configuration.cs:line 41
at LibGit2Sharp.Configuration..ctor(String globalConfigurationFileLocation, String xdgConfigurationFileLocation, String systemConfigurationFileLocation) in C:\Users\jamill\gitWorkspaces\libgit2sharp\LibGit2Sharp\Configuration.cs:line 100
at Castle.Proxies.ConfigurationProxy..ctor(IInterceptor[] , String , String , String )
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(Type proxyType, List`1 proxyArguments, Type classToProxy, Object[] constructorArguments)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
at Moq.Proxy.CastleProxyFactory.CreateProxy(Type mockType, ICallInterceptor interceptor, Type[] interfaces, Object[] arguments)
at Moq.Mock`1.<InitializeInstance>b__2()
at Moq.PexProtector.Invoke(Action action)
at Moq.Mock`1.InitializeInstance()
at Moq.Mock`1.OnGetObject()
at Moq.Mock`1.get_Object()
at LibGit2Sharp.Tests.MockingFixture.CanFakeEnumerationOfConfiguration() in C:\Users\jamill\gitWorkspaces\libgit2sharp\LibGit2Sharp.Tests\MockingFixture.cs:line 97
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Xunit.Sdk.Reflector.ReflectionMethodInfo.Invoke(Object testClass, Object[] parameters)
at Xunit.Sdk.FactCommand.Execute(Object testClass)
at Xunit.Sdk.FixtureCommand.Execute(Object testClass)
at Xunit.Sdk.BeforeAfterCommand.Execute(Object testClass)
at Xunit.Sdk.LifetimeCommand.Execute(Object testClass)
at Xunit.Sdk.ExceptionAndOutputCaptureCommand.Execute(Object testClass)
at Xunit.Sdk.TimedCommand.Execute(Object testClass)
at Xunit.Sdk.TestClassCommandRunner.Execute(ITestClassCommand testClassCommand, List`1 methods, Predicate`1 startCallback, Predicate`1 resultCallback)
at Xunit.Sdk.Executor.RunTests.<>c__DisplayClass12.<.ctor>b__f()
at Xunit.Sdk.Executor.ThreadRunner(Object threadStart)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)

@jamill
Copy link
Member

jamill commented May 1, 2015

@shiftkey - I am not completely familiar with this yet, but it looks like the Mock<Config> object is calling the constructor for the class, which in turn allocates a new ConfigurationSafeHandle. My (possibly wrong) expectation is that we do not want the mock to actually initialize itself to this extent? Having the mock call into libgit2 and set up some native structures seems to break the encapsulation of the mock object - maybe we want an IConfig interface?

@shiftkey
Copy link
Contributor

shiftkey commented May 7, 2015

Okay, that should be the fix. I'll try and give it thorough review to ensure the optional combinations are maintained wherever appropriate, but any extra help would be 💖

@shiftkey
Copy link
Contributor

shiftkey commented May 7, 2015

@@ -10,6 +10,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHING_EMPTY_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change do? (asking for a friend)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I found myself dropping the default _ when R# was bugging me during the refactoring. I'll check.

@nulltoken
Copy link
Member Author

Pushed some fixups

@nulltoken
Copy link
Member Author

Anyone opposing to see this pulled in?

@Therzok
Copy link
Member

Therzok commented May 15, 2015

:shipit:

nulltoken added a commit that referenced this pull request May 15, 2015
Ensure lack of optional parameters
@nulltoken nulltoken merged commit 98e6e34 into vNext May 15, 2015
@nulltoken nulltoken deleted the ntk/optionals branch May 15, 2015 18:02
@nulltoken
Copy link
Member Author

@shiftkey AWE. SOME! 💯 🎱

@nulltoken nulltoken added this to the v0.22 milestone May 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants