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

Add Nightly Tests for Humanizer #7627

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<SystemCollectionsImmutableVersion>6.0.0</SystemCollectionsImmutableVersion>
<SystemRuntimeCompilerServicesUnsafeVersion>6.0.0</SystemRuntimeCompilerServicesUnsafeVersion>
<ELFSharpVersion>2.13.1</ELFSharpVersion>
<HumanizerVersion>2.14.1</HumanizerVersion>
<MdocPackageVersion Condition=" '$(MdocPackageVersion)' == '' ">5.8.9.2</MdocPackageVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,33 @@ public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblySto
};
proj.SetProperty ("AndroidUseAssemblyStore", usesAssemblyStores.ToString ());
proj.SetAndroidSupportedAbis ("armeabi-v7a");
proj.PackageReferences.Add (new Package {
Id = "Humanizer.Core",
Version = "2.14.1",
});
proj.PackageReferences.Add (new Package {
Id = "Humanizer.Core.es",
Version = "2.14.1",
});
proj.MainActivity = proj.DefaultMainActivity
.Replace ("//${USINGS}", @"using System;
using Humanizer;
using System.Globalization;")
.Replace ("//${AFTER_ONCREATE}", @"var c = new CultureInfo (""es-ES"");
Console.WriteLine ($""{DateTime.UtcNow.AddHours(-30).Humanize(culture:c)}"");
//${AFTER_ONCREATE}");
if (Builder.UseDotNet) {
proj.OtherBuildItems.Add (new BuildItem ("Using", "System.Globalization"));
proj.OtherBuildItems.Add (new BuildItem ("Using", "Humanizer"));
}
if (!Builder.UseDotNet) {
proj.PackageReferences.Add (new Package {
Id = "System.Runtime.InteropServices.WindowsRuntime",
Version = "4.0.1",
TargetFramework = "monoandroid71",
});
proj.References.Add (new BuildItem.Reference ("Mono.Data.Sqlite.dll"));
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", "var command = new Mono.Data.Sqlite.SqliteCommand ();");
proj.MainActivity = proj.MainActivity.Replace ("//${AFTER_ONCREATE}", "var command = new Mono.Data.Sqlite.SqliteCommand ();");
}
var expectedFiles = Builder.UseDotNet ?
new [] {
Expand All @@ -95,6 +114,11 @@ public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblySto
"System.Linq.dll",
"UnnamedProject.dll",
"_Microsoft.Android.Resource.Designer.dll",
"Humanizer.dll",
"es/Humanizer.resources.dll",
"System.Collections.dll",
"System.Collections.Concurrent.dll",
"System.Text.RegularExpressions.dll",
} :
new [] {
"Java.Interop.dll",
Expand All @@ -106,6 +130,8 @@ public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblySto
"UnnamedProject.dll",
"Mono.Data.Sqlite.dll",
"Mono.Data.Sqlite.dll.config",
"Humanizer.dll",
//"es/Humanizer.resources.dll", <- Bug in classic.
};
using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ void ArchiveContains (string[] fileNames, out List<string> existingFiles, out Li
{
using (var zip = ZipHelper.OpenZip (archivePath)) {
existingFiles = zip.Where (a => a.FullName.StartsWith (assembliesRootDir, StringComparison.InvariantCultureIgnoreCase)).Select (a => a.FullName).ToList ();
missingFiles = fileNames.Where (x => !zip.ContainsEntry (assembliesRootDir + Path.GetFileName (x))).ToList ();
additionalFiles = existingFiles.Where (x => !fileNames.Contains (Path.GetFileName (x))).ToList ();
missingFiles = fileNames.Where (x => !zip.ContainsEntry (assembliesRootDir + x)).ToList ();
additionalFiles = existingFiles.Where (x => !fileNames.Contains (x.Replace (assembliesRootDir, string.Empty))).ToList ();
}
}

Expand All @@ -258,15 +258,21 @@ void StoreContains (string[] fileNames, out List<string> existingFiles, out List
if (otherFiles.Count > 0) {
using (var zip = ZipHelper.OpenZip (archivePath)) {
foreach (string file in otherFiles) {
string fullPath = assembliesRootDir + Path.GetFileName (file);
string fullPath = assembliesRootDir + file;
if (zip.ContainsEntry (fullPath)) {
existingFiles.Add (file);
}
}
}
}

var explorer = new AssemblyStoreExplorer (archivePath);
var explorer = new AssemblyStoreExplorer (archivePath, customLogger: (a, s) => {
Console.WriteLine ($"DEBUG! {s}");
});

foreach (var f in explorer.AssembliesByName) {
Console.WriteLine ($"DEBUG!\tKey:{f.Key}");
}

// Assembly stores don't store the assembly extension
var storeAssemblies = explorer.AssembliesByName.Keys.Select (x => $"{x}.dll");
Expand Down Expand Up @@ -298,7 +304,7 @@ void StoreContains (string[] fileNames, out List<string> existingFiles, out List
}

foreach (string file in fileNames) {
if (existingFiles.Contains (Path.GetFileName (file))) {
if (existingFiles.Contains (file)) {
continue;
}
missingFiles.Add (file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<ItemGroup>
<PackageReference Include="ELFSharp" Version="$(ELFSharpVersion)" />
<PackageReference Include="ICSharpCode.Decompiler" Version="7.2.1.6856" />
<PackageReference Include="Humanizer" Version="$(HumanizerVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Android.Views;
using Android.Widget;
using Android.OS;
//${USINGS}

namespace ${ROOT_NAMESPACE}
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//${USINGS}
namespace ${ROOT_NAMESPACE}
{
[Android.Runtime.Register ("${JAVA_PACKAGENAME}.MainActivity"), Activity (Label = "${PROJECT_NAME}", MainLauncher = true, Icon = "@drawable/icon")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Android.Views;
using Android.Widget;
using Android.OS;
//${USINGS}

namespace ${ROOT_NAMESPACE}
{
Expand All @@ -23,4 +24,4 @@ protected override void OnCreate (Bundle savedInstanceState)
LoadApplication (new App ());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Android.Support.Wearable.Views;
using Android.Views;
using Android.Widget;
//${USINGS}

namespace ${ROOT_NAMESPACE}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<PackageReference Include="NodaTime" Version="2.4.5" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.1.787" />
<PackageReference Include="ICSharpCode.Decompiler" Version="7.2.1.6856" />
<PackageReference Include="Humanizer" Version="$(HumanizerVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
27 changes: 25 additions & 2 deletions tests/MSBuildDeviceIntegration/Tests/LocalizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using Xamarin.ProjectTools;
using Humanizer;

namespace Xamarin.Android.Build.Tests
{
Expand All @@ -30,14 +31,23 @@ public void BeforeAllTests ()
}

proj = new XamarinAndroidApplicationProject (packageName: "LocalizationTests");
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @"button.Text = $""Strings.SomeString={Strings.SomeString}"";
proj.PackageReferences.Add (new Package {
Id = "Humanizer",
Version = "2.14.1",
});
var source = proj.DefaultMainActivity
.Replace ("//${USINGS}", @"using Humanizer;
using System.Globalization;");
source = source.Replace ("//${AFTER_ONCREATE}", @"button.Text = $""Strings.SomeString={Strings.SomeString}"";
Console.WriteLine ($""LocaleNative={Java.Util.Locale.Default.Language}-{Java.Util.Locale.Default.Country}"");
Console.WriteLine ($""CurrentCulture={System.Globalization.CultureInfo.CurrentCulture.Name}"");
Console.WriteLine ($""Strings.SomeString={Strings.SomeString}"");
Console.WriteLine ($""Humanizer={DateTime.UtcNow.AddHours(-30).Humanize()}"");
");
proj.MainActivity = source;
InlineData.AddCultureResourcesToProject (proj, "Strings", "SomeString");
InlineData.AddCultureResourceDesignerToProject (proj, proj.RootNamespace ?? proj.ProjectName, "Strings", "SomeString");

builder = CreateApkBuilder (Path.Combine ("temp", "LocalizationTests"));
builder.BuildLogFile = "onetimesetup-install.log";
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
Expand Down Expand Up @@ -247,8 +257,21 @@ public void CheckLocalizationIsCorrect (string locale)
}
return false;
}, appStartupLogcatFile, 45), $"App output did not contain '{logcatSearchString}'");
Assert.IsTrue (logLine.Contains (expectedLogcatOutput), $"Line '{logLine}' did not contain '{expectedLogcatOutput}'");

string humanizerLogCatFile = Path.Combine (Root, builder.ProjectDirectory, $"humanizer-logcat-{locale.Replace ("/", "-")}.log");
var culture = new CultureInfo (locale);
expectedLogcatOutput = DateTime.UtcNow.AddHours(-30).Humanize(culture: culture);
logcatSearchString = "Humanizer=";
Assert.IsTrue (MonitorAdbLogcat ((line) => {
if (line.Contains (logcatSearchString)) {
logLine = line;
return true;
}
return false;
}, humanizerLogCatFile, timeout:45), $"App output did not contain '{logcatSearchString}'");
Assert.IsTrue (logLine.Contains (expectedLogcatOutput), $"Line '{logLine}' did not contain '{expectedLogcatOutput}'");

}
}
}