Skip to content

Commit

Permalink
remove RoslynCodeTaskFactory tests to see if Windows Core and Windows…
Browse files Browse the repository at this point in the history
… Full fail or not
  • Loading branch information
surayya-MS committed Feb 16, 2024
1 parent 4e6191c commit 601d3d1
Showing 1 changed file with 0 additions and 118 deletions.
118 changes: 0 additions & 118 deletions src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,124 +644,6 @@ public override bool Execute()
}
}

[Fact]
public void EmbedsSourceFileInBinlog()
{
string taskName = "HelloTask";
string csprojFileName = "EmbedsSourceFileInTheBinlogTest.csproj";
string targetName = "SayHello";

var env = TestEnvironment.Create();
TransientTestFolder folder = env.CreateFolder(createFolder: true);
TransientTestFile taskClass = env.CreateFile(folder, $"{taskName}.cs", $$"""
namespace InlineTask
{
using Microsoft.Build.Utilities;

public class {{taskName}} : Task
{
public override bool Execute()
{
Log.LogMessage("Hello, world!");
return !Log.HasLoggedErrors;
}
}
}
""");
TransientTestFile assemblyProj = env.CreateFile(folder, csprojFileName, $"""
<Project>

<UsingTask
TaskName="{taskName}"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<Task>
<Code Type="Class" Language="cs" Source="{taskClass.Path}">
</Code>
</Task>
</UsingTask>

<Target Name="{targetName}">
<{taskName} />
</Target>

</Project>
""");

string binLogFile = Path.Combine(folder.Path, "log.binlog");
string output = RunnerUtilities.ExecMSBuild($"{assemblyProj.Path} /t:{targetName} /bl:\"LogFile={binLogFile};ProjectImports=ZipFile\"", out bool success);

success.ShouldBeTrue();

string projectImportsZipPath = Path.ChangeExtension(binLogFile, ".ProjectImports.zip");
using var fileStream = new System.IO.FileStream(projectImportsZipPath, System.IO.FileMode.Open);
using var zipArchive = new System.IO.Compression.ZipArchive(fileStream, System.IO.Compression.ZipArchiveMode.Read);

// Can't just compare `Name` because `ZipArchive` does not handle unix directory separators well
// thus producing garbled fully qualified paths in the actual .ProjectImports.zip entries
zipArchive.Entries.ShouldContain(zE => zE.Name.EndsWith($"{taskName}.cs"),
"");
}

[Fact]
public void EmbedsSourceFileInBinlogWhenFailsToCompile()
{
string taskName = "HelloTask";
string csprojFileName = "EmbedsSourceFileInTheBinlogTest.csproj";
string targetName = "SayHello";

var env = TestEnvironment.Create();
TransientTestFolder folder = env.CreateFolder(createFolder: true);
TransientTestFile classThatFailsToCompile = env.CreateFile(folder, $"{taskName}.cs", $$"""
namespace InlineTask
{
using Microsoft.Build.Utilities

public class {{taskName}} : Task
{
public override bool Execute()
{
Log.LogMessage("Hello, world!")
return !Log.HasLoggedErrors
}
}
}
""");
TransientTestFile assemblyProj = env.CreateFile(folder, csprojFileName, $"""
<Project>

<UsingTask
TaskName="{taskName}"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<Task>
<Code Type="Class" Language="cs" Source="{classThatFailsToCompile.Path}">
</Code>
</Task>
</UsingTask>

<Target Name="{targetName}">
<{taskName} />
</Target>

</Project>
""");

string binLogFile = Path.Combine(folder.Path, "log.binlog");
string output = RunnerUtilities.ExecMSBuild($"{assemblyProj.Path} /t:{targetName} /bl:\"LogFile={binLogFile};ProjectImports=ZipFile\"", out bool success);

success.ShouldBeFalse();

string projectImportsZipPath = Path.ChangeExtension(binLogFile, ".ProjectImports.zip");
using var fileStream = new System.IO.FileStream(projectImportsZipPath, System.IO.FileMode.Open);
using var zipArchive = new System.IO.Compression.ZipArchive(fileStream, System.IO.Compression.ZipArchiveMode.Read);

// Can't just compare `Name` because `ZipArchive` does not handle unix directory separators well
// thus producing garbled fully qualified paths in the actual .ProjectImports.zip entries
zipArchive.Entries.ShouldContain(zE => zE.Name.EndsWith($"{taskName}.cs"),
"");
}

#if !FEATURE_RUN_EXE_IN_TESTS
[Fact]
public void RoslynCodeTaskFactory_UsingAPI()
Expand Down

0 comments on commit 601d3d1

Please sign in to comment.