Skip to content
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

Fixes #2600 #2690

Conversation

yazeedobaid
Copy link
Collaborator

Description

After a hint from @michaelsmithson in this comment, we found the source of the issue that causes the NUnit Console runner to fail.

I commented out that call for withEnvironment in create process and it indeed runs the tests in the given repro repository successfully without issues.

Also, replacing withEnvironment with withEnvironmentMap runs successfully without issues. Further debugging the issue and I got a duplicate item error as shown below:

System.ArgumentException: An item with the same key has already been added.
at System.Runtime.CompilerServices.ConditionalWeakTable`2.Add(TKey key, TValue value)
at Microsoft.FSharp.Control.ExceptionDispatchInfoHelpers.ExceptionDispatchInfo.GetAssociatedSourceException(ExceptionDispatchInfo ) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 48

The withEnvironment method calls EnvMap.ofSeq from the Process module which has the following implementation:

let ofSeq l : EnvMap =
        empty.AddRange(l |> Seq.map (fun (k, v) -> KeyValuePair<_,_>(k, v)))

The empty is a new instance of ImmutableDictionary.

Comparing withEnvironment with withEnvironmentMap implemntations and the only difference is that, before adding the list of given environment variables, the withEnvironmentMap initializes the immutable collection with environment variables.

So, trying to add Clear before adding the given list of environment variables in ofSeq with no luck, Also, checking items in the collection before adding an item and skipping any duplicates, resulted in the same error.

What I ended up doing is initializing the empty immutable collection with environment variables before adding the given environment list. Same as withEnvironmentMap

Another solution would be to just replace the withEnvironment with withEnvironmentMap in NUnit create process. But this will not solve the issue from its roots.

TODO

Feel free to open the PR and ask for help

  • New (API-)documentation for new features exist (Note: API-docs are enough, additional docs are in help/markdown)

  • unit or integration test exists (or short reasoning why it doesn't make sense)

    Note: Consider using the CreateProcess API which can be tested more easily, see https:/fsharp/FAKE/pull/2131/files#diff-4fb4a77e110fbbe8210205dfe022389b for an example (the changes in the DotNet.Testing.NUnit module)

  • boy scout rule: "leave the code behind in a better state than you found it" (fix warnings, obsolete members or code-style in the places you worked in)

  • (if new module) the module has been linked from the "Modules" menu, edit help/templates/template.cshtml, linking to the API-reference is fine.

  • (if new module) the module is in the correct namespace

  • (if new module) the module is added to Fake.sln (dotnet sln Fake.sln add src/app/Fake.*/Fake.*.fsproj)

  • Fake 5 API guideline is honored

A duplicate item is thrown when calling `withEnvironment` from NUnit. Empty dictionary is causing issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NUnit3 Module call to console runner fails with FileLoadException
1 participant