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

Update to the RewriteTests test cases to actually invoke the newly rewritten assembly #52

Merged
merged 4 commits into from
May 18, 2019

Conversation

toptensoftware
Copy link
Contributor

@toptensoftware toptensoftware commented May 17, 2019

Note: this approach requires one small (but worthwhile) change to ILPack to allow it to rename the assembly and namespace meta data that it generates. This allows the test runner to load both the original and the cloned assembly without needing AppDomain support (which netcore doesn't have).

Overall this is a much cleaner approach than previous pull request #51 which I've retracted. Also I've removed the original test cases from RewriteTests which weren't really effective in detecting problems and this new approach should cover everything they did anyway.

The notes below are copied from comments included in the RewriteTests.cs test case file.

Finally, note that some of the test cases included here are failing, but they're separate issues to this pull request.


These test cases work by taking the RewriteOriginal project, passing it
through ILPack to generate a new assembly and then checking that the
newly generated assembly is correct by actually loading it and invoking
methods and properties on it.

It works as follows:

  1. RewriteOriginal.dll is loaded through a project reference and found
    with a simple typeof(MyClass)

  2. ILPack is used to to rewrite a new assembly RewriteClone.dll

  3. To allow the second DLL to be loaded into the same process (we don't
    have AppDomains under net core), we use ILPack's RenameForTesting method
    to change the names of the assembly and the contained namespace(s)

  4. Use CSharpScript to load the newly cloned assembly and poke it in
    various ways to make sure it still works.

Also, in the Lokad.ILPack.Tests project folder there's a dump.bat script
which on Windows will run ildasm and mddumper on both the original and the
cloned assemblies. Handy for comparison when diagnosing issues. (ildasm
and mddumper both need to be on your path)

Copy link
Member

@vermorel vermorel left a comment

Choose a reason for hiding this comment

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

The CSharp.Scripting approach is indeed much more elegant. That's very nice!

@@ -19,6 +19,27 @@ private void Initialize(Assembly assembly)
_debugDirectoryBuilder = new DebugDirectoryBuilder();
}

// Called by the unit tests to rename the assembly and the namespaces
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to use the syntax /// <summary> ... </summary>; as it plays nicely with VS Intellisence.

using Xunit;

namespace Lokad.ILPack.Tests
{
/*
Copy link
Member

Choose a reason for hiding this comment

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

Nicely detailed explanation!

@vermorel vermorel merged commit 1746333 into Lokad:master May 18, 2019
@toptensoftware toptensoftware deleted the InvokeRewrittenTestAssembly2 branch May 18, 2019 11:02
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.

2 participants