Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/dotnet/UnitTests/WindowsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ class FileData {
public required string RelativePath;
}

static (DateTime TimestampUtc, string Contents) GetFileState (string path, string message)
{
Assert.That (path, Does.Exist, $"{message}: missing file");
return (File.GetLastWriteTimeUtc (path), File.ReadAllText (path));
}

static void AssertFileStateUnchanged ((DateTime TimestampUtc, string Contents) previousState, string path, string message)
{
Assert.That (path, Does.Exist, $"{message}: missing file");

var currentTimestamp = File.GetLastWriteTimeUtc (path);
var currentContents = File.ReadAllText (path);

Assert.Multiple (() => {
Assert.That (
currentTimestamp,
Is.EqualTo (previousState.TimestampUtc),
$"{message}: timestamp changed for '{path}' (before: {previousState.TimestampUtc:o}; after: {currentTimestamp:o})");
Assert.That (currentContents, Is.EqualTo (previousState.Contents), $"{message}: contents changed for '{path}'");
});
}

void AssertMaxFileLengthInBinAndObjDirectories (ApplePlatform platform, string project_path, string runtimeIdentifiers, string configuration, int maxLength = 118)
{
var binDir = GetBinDir (project_path, platform, runtimeIdentifiers, configuration);
Expand Down Expand Up @@ -155,11 +177,28 @@ public void BundleStructureWithRemoteMac (ApplePlatform platform, string runtime
var objDir = GetObjDir (project_path, platform, runtimeIdentifiers, configuration);
var zippedAppBundlePath = Path.Combine (objDir, "AppBundle.zip");
Assert.That (zippedAppBundlePath, Does.Exist, "AppBundle.zip");
var appManifestPath = Path.Combine (objDir, "AppManifest.plist");
var compileAppManifestInputsPath = Path.Combine (objDir, "_CompileAppManifest.inputs");
var sharedDotNetPlistPath = Path.Combine (objDir, "unpack", "bindings-framework-test", "PartialAppManifest", "shared-dotnet.plist");

BundleStructureTest.CheckZippedAppBundleContents (platform, zippedAppBundlePath, rids, signature, isReleaseBuild);
AssertWarningsEqual (expectedWarnings, warningMessages, "Warnings");
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);

// These files participate in _CompileAppManifest incrementality, so verify that they stay stable when we only
// touch code. If this test flakes again, these assertions should tell us which input changed unexpectedly.
var appManifestState = GetFileState (appManifestPath, "Initial build: AppManifest.plist");
var compileAppManifestInputsState = GetFileState (compileAppManifestInputsPath, "Initial build: _CompileAppManifest.inputs");
var sharedDotNetPlistState = GetFileState (sharedDotNetPlistPath, "Initial build: shared-dotnet.plist");

Assert.Multiple (() => {
Assert.That (
appManifestState.TimestampUtc,
Is.GreaterThanOrEqualTo (sharedDotNetPlistState.TimestampUtc),
$"Initial build: '{appManifestPath}' should not be older than '{sharedDotNetPlistPath}' (AppManifest.plist: {appManifestState.TimestampUtc:o}; shared-dotnet.plist: {sharedDotNetPlistState.TimestampUtc:o})");
Assert.That (compileAppManifestInputsState.Contents, Does.Contain ("shared-dotnet.plist"), "Initial build: _CompileAppManifest.inputs should include shared-dotnet.plist");
});

// Verify that we don't create files with long paths inside bin/obj
AssertMaxFileLengthInBinAndObjDirectories (platform, project_path, runtimeIdentifiers, configuration);

Expand All @@ -174,6 +213,9 @@ public void BundleStructureWithRemoteMac (ApplePlatform platform, string runtime

BundleStructureTest.CheckZippedAppBundleContents (platform, zippedAppBundlePath, rids, signature, isReleaseBuild);
AssertWarningsEqual (expectedWarnings, warningMessages, "Warnings Rebuild 1");
AssertFileStateUnchanged (sharedDotNetPlistState, sharedDotNetPlistPath, "Rebuild 1: shared-dotnet.plist");
AssertFileStateUnchanged (compileAppManifestInputsState, compileAppManifestInputsPath, "Rebuild 1: _CompileAppManifest.inputs");
AssertFileStateUnchanged (appManifestState, appManifestPath, "Rebuild 1: AppManifest.plist");
AssertTargetNotExecuted (allTargets, "_CompileAppManifest", "_CompileAppManifest Rebuild 1");
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);

Expand All @@ -191,6 +233,9 @@ public void BundleStructureWithRemoteMac (ApplePlatform platform, string runtime

BundleStructureTest.CheckZippedAppBundleContents (platform, zippedAppBundlePath, rids, signature, isReleaseBuild);
AssertWarningsEqual (expectedWarnings, warningMessages, "Warnings Rebuild 2");
AssertFileStateUnchanged (sharedDotNetPlistState, sharedDotNetPlistPath, "Rebuild 2: shared-dotnet.plist");
AssertFileStateUnchanged (compileAppManifestInputsState, compileAppManifestInputsPath, "Rebuild 2: _CompileAppManifest.inputs");
AssertFileStateUnchanged (appManifestState, appManifestPath, "Rebuild 2: AppManifest.plist");
AssertTargetNotExecuted (allTargets, "_CompileAppManifest", "_CompileAppManifest Rebuild 2");
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);

Expand All @@ -205,6 +250,9 @@ public void BundleStructureWithRemoteMac (ApplePlatform platform, string runtime

BundleStructureTest.CheckZippedAppBundleContents (platform, zippedAppBundlePath, rids, signature, isReleaseBuild);
AssertWarningsEqual (expectedWarnings, warningMessages, "Warnings Rebuild 3");
AssertFileStateUnchanged (sharedDotNetPlistState, sharedDotNetPlistPath, "Rebuild 3: shared-dotnet.plist");
AssertFileStateUnchanged (compileAppManifestInputsState, compileAppManifestInputsPath, "Rebuild 3: _CompileAppManifest.inputs");
AssertFileStateUnchanged (appManifestState, appManifestPath, "Rebuild 3: AppManifest.plist");
AssertTargetNotExecuted (allTargets, "_CompileAppManifest", "_CompileAppManifest Rebuild 3");
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);

Expand Down
Loading