-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add Rebuild.UnitTests #51778
Add Rebuild.UnitTests #51778
Conversation
var (compilation, isError) = bc.CreateCompilation(optionsReader, "test", sources, references); | ||
|
||
Assert.False(isError); | ||
Assert.Equal(platform, compilation!.Options.Platform); |
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.
Think we need to take the next step and ensuring the original and rebuilt compilation have the same byte[]
output. Consider doing as a helper so future tests can just build on top of that.
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 think this is a good idea, but there are issues with it to iron out that I'm not sure I want to block on.
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.
Fine on working it out later but let's file an issue to track.
namespace Rebuild.UnitTests | ||
{ | ||
//[CompilerTrait(CompilerFeature.)] | ||
public class CSharpRebuildTests : CSharpTestBase |
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.
What about VB
tests here?
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 think it would be good to have a VB version of this test. I guess in that case we'd want to add a reference to the VB test helpers?
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.
My instinct was to have an abstract
base class and then have both a VB and C# derivation. Hoping that it would be easy to abstract over the languages this way.
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'd like to introduce a few more test cases and then try to figure out what test helpers would be most useful.
Co-authored-by: Jared Parsons <jaredpparsons@gmail.com>
@jaredpar have responded to the feedback. |
@@ -2,6 +2,8 @@ | |||
// The .NET Foundation licenses this file to you under the MIT license. | |||
// See the LICENSE file in the project root for more information. | |||
|
|||
using Roslyn.Utilities; |
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.
Roslyn.Utilities [](start = 6, length = 16)
Is this needed?
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.
No, thanks, have removed.
@@ -176,6 +177,11 @@ private static (OptimizationLevel, bool) GetOptimizationLevel(string? optimizati | |||
_ => throw new InvalidDataException($"Optimization \"{optimizationLevel}\" level not recognized") | |||
}; | |||
|
|||
private static Platform GetPlatform(string? platform) | |||
=> platform is null |
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.
=> [](start = 8, length = 3)
Should this be indented? #Closed
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.
Fixed.
<ProjectReference Include="..\Rebuild\Rebuild.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Moq" Version="$(MoqVersion)" /> |
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.
[](start = 4, length = 58)
Is this package used? #Closed
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.
Removed.
|
||
var factory = LoggerFactory.Create(configure => { }); | ||
var logger = factory.CreateLogger(path); | ||
// TODO: shouldn't need to pass a logger. |
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.
If we need an ILogger
instance, could we create a simple implementation of ILogger
in this test class?
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.
Yes, but it feels like users of the public API shouldn't be required to provide a logger, and shouldn't provide it as its own parameter. Maybe a property on an options object that can be specified if the user wants, but not a parameter to public API that they have to deal with.
{ | ||
var text = st.GetText(); | ||
return new ResolvedSource(OnDiskPath: null, text, new SourceFileInfo(path, text.ChecksumAlgorithm, text.GetChecksum().ToArray(), text, embeddedCompressedHash: null)); | ||
}).ToImmutableArray(); |
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.
ToImmutableArray [](start = 15, length = 16)
Could use SyntaxTrees.SelectAsArray(...)
instead.
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 think this project is missing an IVT to MS.CA for this. I will punt on it for now if that's ok.
@@ -888,6 +888,9 @@ private void EmbedCompilationOptions(BlobReader? pdbCompilationOptionsReader, Co | |||
WriteValue(CompilationOptionNames.Optimization, optimizationLevel.ToPdbSerializedString(debugPlusMode)); | |||
} | |||
|
|||
var platform = module.CommonCompilation.Options.Platform; | |||
WriteValue(CompilationOptionNames.Platform, platform.ToString()); |
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.
Platform can't be determined from the CLR/PE header flags of the dll? Seems like it should be possible.
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.
It may be possible, but I wasn't able to get all the values to round trip. The CoffHeader.Machine, for example, is not enough information. There must be other bits that imply Platform.AnyCpu
and Platform.AnyCpu32BitPreferred
that I just wasn't able to find.
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.
These are stored in CorHeader flags:
https://source.dot.net/#System.Reflection.Metadata/System/Reflection/PortableExecutable/CorHeader.cs,1f6cfc9c2185aaf4,references
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.
Filed #51941 to make sure we get to this. Thanks
Currently cases(edit: now are all passing.)X86
andAnyCpu32BitPreferred
are failing.I can't quite figure out how to implement GetPlatform to make all these values round trip. In particular struggling to figure out how to distinguish the AnyCpu case from the X86 case. It seems like when
Platform.AnyCpu
is provided as an input, we translate it toMachine.Unknown
:roslyn/src/Compilers/Core/Portable/Compilation/Compilation.cs
Lines 1971 to 1973 in b6f8504
However, when I try to read the Machine value back out of the PE later on, it ends up being
Machine.I386
... I am really not sure what I'm missing or where the value is getting changed.@jaredpar for review.