Skip to content

Commit

Permalink
[tests] use the 'TestName' property (#9664)
Browse files Browse the repository at this point in the history
Context: dotnet/msbuild#11237

In .NET 10, we noticed there is a bug if a project contains `(` or `)` in the path.

We had various tests that were not using `TestName` to sanitize the path.

We have existing tests that do test `(` and `)` characters, which we have left in place.
  • Loading branch information
dellis1972 authored Jan 10, 2025
1 parent 6065242 commit 3830592
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public void CheckOldResourceDesignerIsNotUsed ([Values (true, false)] bool isRel
};
proj.SetProperty ("AndroidUseIntermediateDesignerFile", "True");
proj.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", "False");
using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var b = CreateApkBuilder ()) {
var designer = Path.Combine ("Resources", "Resource.designer" + proj.Language.DefaultDesignerExtension);
if (File.Exists (designer))
File.Delete (Path.Combine (Root, b.ProjectDirectory, designer));
Expand All @@ -582,7 +582,7 @@ public void CheckOldResourceDesignerWithWrongCasingIsRemoved ([Values (true, fal
};
proj.SetProperty ("AndroidUseIntermediateDesignerFile", "True");
proj.SetProperty ("AndroidResgenFile", "Resources\\Resource.designer" + proj.Language.DefaultDesignerExtension);
using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var b = CreateApkBuilder ()) {
var designer = proj.Sources.FirstOrDefault (x => x.Include() == "Resources\\Resource.designer" + proj.Language.DefaultDesignerExtension);
designer = designer ?? proj.OtherBuildItems.FirstOrDefault (x => x.Include () == "Resources\\Resource.designer" + proj.Language.DefaultDesignerExtension);
Assert.IsNotNull (designer, $"Failed to retrieve the Resource.designer.{proj.Language.DefaultDesignerExtension}");
Expand Down Expand Up @@ -1179,7 +1179,7 @@ public void CheckInvalidXmlInManagedResourceParser ()
public void LightlyModifyLayout ()
{
var proj = new XamarinAndroidApplicationProject ();
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "first build should have succeeded");

//Just change something, doesn't matter
Expand All @@ -1198,7 +1198,7 @@ public void CustomViewAddResourceId ()
var proj = new XamarinAndroidApplicationProject ();
proj.LayoutMain = proj.LayoutMain.Replace ("</LinearLayout>", "<android.support.design.widget.BottomNavigationView android:id=\"@+id/navigation\" /></LinearLayout>");
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat);
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
using (var b = CreateApkBuilder ()) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "first build should have succeeded");

Expand Down Expand Up @@ -1227,7 +1227,7 @@ public void CustomViewAddResourceId ()
public void CheckNoVersionVectors ()
{
var proj = new XamarinFormsAndroidApplicationProject ();
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
using (var b = CreateApkBuilder ()) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public void BuildAfterUpgradingNuget ()
Version = "1.6.1.5",
});

using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
//[TearDown] will still delete if test outcome successful, I need logs if assertions fail but build passes
b.CleanupAfterSuccessfulBuild =
b.CleanupOnDispose = false;
Expand Down Expand Up @@ -841,7 +841,7 @@ public void Dispose ()
}
}
}" });
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
builder.ThrowOnBuildFailure = false;
Assert.IsFalse (builder.Build (proj), "Build should have failed with XA4212.");
StringAssertEx.Contains ($"error : XA4", builder.LastBuildOutput, "Error should be XA4212");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ public void BuildApplicationWithLibraryAndClean ([Values (false, true)] bool isR
ProjectName = "App1",
References = { new BuildItem ("ProjectReference", "..\\Library1\\Library1.csproj") },
};
var projectPath = Path.Combine ("temp", TestContext.CurrentContext.Test.Name);
var projectPath = Path.Combine ("temp", TestName);
using (var libb = CreateDllBuilder (Path.Combine (projectPath, lib.ProjectName), false, false)) {
Assert.IsTrue (libb.Build (lib), "Build of library should have succeeded");
using (var b = CreateApkBuilder (Path.Combine (projectPath, proj.ProjectName), false, false)) {
Expand Down Expand Up @@ -1382,7 +1382,7 @@ public void BuildAppCheckDebugSymbols ()
{
AssertCommercialBuild (); // FIXME: when Fast Deployment isn't available, we would need to use `llvm-objcopy` to extract the debug symbols

var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name);
var path = Path.Combine ("temp", TestName);
var lib = new XamarinAndroidLibraryProject () {
IsRelease = false,
ProjectName = "Library1",
Expand Down Expand Up @@ -1552,7 +1552,7 @@ public void BuildWithJavaToolOptions ()
[Test]
public void LibraryWithGenericAttribute ()
{
var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name);
var path = Path.Combine ("temp", TestName);
var lib = new XamarinAndroidLibraryProject {
ProjectName = "Library1",
IsRelease = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public void BuildWithNativeLibraryUnknownAbi ()
};
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");

using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
builder.ThrowOnBuildFailure = false;
Assert.IsFalse (builder.Build (proj), "Build should have failed.");
Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, $"error XA4301: Cannot determine ABI of native library 'not-a-real-abi{Path.DirectorySeparatorChar}libtest.so'. Move this file to a directory with a valid Android ABI name such as 'libs/armeabi-v7a/'."),
Expand Down Expand Up @@ -502,7 +502,7 @@ public void AndroidLibraryProjectsZipWithOddPaths ()
TextContent = () => $@"
<Project>
<PropertyGroup>
<IntermediateOutputPath>$(MSBuildThisFileDirectory)../{TestContext.CurrentContext.Test.Name}/obj/$(Configuration)/foo/</IntermediateOutputPath>
<IntermediateOutputPath>$(MSBuildThisFileDirectory)../{TestName}/obj/$(Configuration)/foo/</IntermediateOutputPath>
</PropertyGroup>
</Project>"
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ public void ManifestDataPathError ()
</activity>
</application>");
proj.AndroidManifest = s;
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
builder.ThrowOnBuildFailure = false;
Assert.IsFalse (builder.Build (proj), "Build should have failed.");
var messages = builder.LastBuildOutput.SkipWhile (x => !x.StartsWith ("Build FAILED.", StringComparison.Ordinal));
Expand Down Expand Up @@ -621,7 +621,7 @@ public void ManifestPlaceHolders2 ()
Assert.AreNotEqual (proj.AndroidManifest, s, "#0");
proj.SetProperty ("AndroidManifestPlaceholders", "FOOBARNAME=AAAAAAAA");
proj.AndroidManifest = s;
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name), false, false)) {
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName), false, false)) {
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
var manifest = builder.Output.GetIntermediaryAsText (Root, "android/AndroidManifest.xml");
Assert.IsTrue (manifest.Contains ("AAAAAAAA"), "#1");
Expand Down Expand Up @@ -745,7 +745,7 @@ public void MergeLibraryManifest ()
}
data = ms.ToArray ();
}
var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name);
var path = Path.Combine ("temp", TestName);
var lib = new XamarinAndroidBindingProject () {
ProjectName = "Binding1",
AndroidClassParser = "class-parse",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
if (useApkSigner && !foundApkSigner) {
Assert.Ignore ("Skipping test. Required build-tools verison which contains apksigner is not installed.");
}
string keyfile = Path.Combine (Root, "temp", TestName, "release.keystore");
string keyfile = Path.Combine (Root, "temp", TestName, "keystore", "release.keystore");
if (File.Exists (keyfile))
File.Delete (keyfile);
string keyToolPath = Path.Combine (AndroidSdkResolver.GetJavaSdkPath (), "bin");
Expand Down Expand Up @@ -397,7 +397,7 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
} else {
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");
}
using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName, "App"))) {
var bin = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath);
Assert.IsTrue (b.Build (proj), "First build failed");
b.AssertHasNoWarnings ();
Expand Down
4 changes: 2 additions & 2 deletions tests/MSBuildDeviceIntegration/Tests/InstallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void InstallErrorCode ()
};
proj.SetAndroidSupportedAbis (abi);

using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
builder.ThrowOnBuildFailure = false;
if (!builder.Install (proj)) {
Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, "ADB0020"), "Should receive ADB0020 error code.");
Expand All @@ -247,7 +247,7 @@ public void ToggleFastDev ()
}
};

using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
var directorylist = GetContentFromAllOverrideDirectories (proj.PackageName, DeviceAbi);
StringAssert.Contains ($"{proj.ProjectName}.dll", directorylist, $"{proj.ProjectName}.dll should exist in the .__override__ directory.");
Expand Down

0 comments on commit 3830592

Please sign in to comment.