Skip to content

Commit

Permalink
Allow building with .net 6.0
Browse files Browse the repository at this point in the history
- Add net6.0 to tests
- allow to build and run tests with `dotnet`
- fix failing tests with net6.0 - at least partially caused by
  a too long message for `IgnoreAttribute`
- move native tests to `NativeMethods` subdirectory
- remove `icu.net.netstandard.testrunner` project since it's now
  possible to run .NET Core tests with `dotnet test`
- implement `DllResolver` to resolve native libraries on .NET Core

+semver:minor
  • Loading branch information
ermshiperete committed Aug 4, 2022
1 parent ea985f1 commit 0ab57ff
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 95 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Support .net 6.0

## [2.8.1] - 2022-07-08

### Fixed
Expand Down
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Overview

icu-dotnet is the C# wrapper for a subset of [ICU](https://icu.unicode.org/).
>ICU is a mature, widely used set of C/C++ and Java libraries providing Unicode and Globalization support for software applications. ICU is widely portable and gives applications the same results on all platforms and between C/C++ and Java software.

> ICU is a mature, widely used set of C/C++ and Java libraries providing Unicode and Globalization support
> for software applications. ICU is widely portable and gives applications the same results on all platforms
> and between C/C++ and Java software.
## Status

Expand All @@ -28,31 +31,32 @@ Similarly, it might be beneficial to call `Icu.Wrapper.Cleanup()` before exiting
Sample code:

``` csharp
static class Program
{
public static void Main(string[] args)
{
Icu.Wrapper.Init();
// Will output "NFC form of XA\u0308bc is XÄbc"
Console.WriteLine($"NFC form of XA\\u0308bc is {Icu.Normalizer.Normalize("XA\u0308bc",
Icu.Normalizer.UNormalizationMode.UNORM_NFC)}");
Icu.Wrapper.Cleanup();
}
}
static class Program
{
public static void Main(string[] args)
{
Icu.Wrapper.Init();
// Will output "NFC form of XA\u0308bc is XÄbc"
Console.WriteLine($"NFC form of XA\\u0308bc is {Icu.Normalizer.Normalize("XA\u0308bc",
Icu.Normalizer.UNormalizationMode.UNORM_NFC)}");
Icu.Wrapper.Cleanup();
}
}
```

## Building

icu-dotnet can be built with Visual Studio or MonoDevelop, but at least initially it might be
easier to build from the command line because that will download all necessary dependencies.
To build the current version of icu-dotnet you'll need .net 6.0 installed.

### Linux
icu-dotnet can be built from the command line as well as Visual Studio or JetBrains Rider.

You can build and run the unit tests by running:
### Windows and Linux

build/TestBuild.sh
You can build and run the unit tests by running:

If you run into issues you might want to try with a newer mono version or with our custom `mono-sil` package from [packages.sil.org](http://packages.sil.org/)
```bash
dotnet test source/icu.net.sln
```

### Docker

Expand All @@ -72,12 +76,6 @@ RUN apt-get update \
...
```

### Windows

Build and run the unit tests by running:

msbuild /t:Test build/icu-dotnet.proj

## ICU versions

### Linux
Expand Down Expand Up @@ -118,7 +116,7 @@ The package installer should have added an import to the `*.csproj` file similar

```xml
<Import Project="..\..\packages\Icu4c.Win.Min.54.1.31\build\Icu4c.Win.Min.targets"
Condition="Exists('..\..\packages\Icu4c.Win.Min.54.1.31\build\Icu4c.Win.Min.targets')" />
Condition="Exists('..\..\packages\Icu4c.Win.Min.54.1.31\build\Icu4c.Win.Min.targets')" />
```

## Contributing
Expand Down
4 changes: 2 additions & 2 deletions source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net40;net451;netstandard1.6</TargetFrameworks>
<TargetFrameworks>net40;net451;netstandard1.6;net6.0</TargetFrameworks>
<PlatformAlias>netstandard</PlatformAlias>
<OutputPath>$(MSBuildThisFileDirectory)\..\output\$(Configuration)</OutputPath>
<PackageOutputPath>$(MSBuildThisFileDirectory)\..\output</PackageOutputPath>
Expand All @@ -17,7 +17,7 @@ See full changelog at https://github.com/sillsdev/icu-dotnet/blob/master/CHANGEL
<ChangelogFile>$(MSBuildThisFileDirectory)/../CHANGELOG.md</ChangelogFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>7.1</LangVersion>
<LangVersion>default</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)/icu.net.snk</AssemblyOriginatorKeyFile>
Expand Down
2 changes: 1 addition & 1 deletion source/TestHelper/TestHelper.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;net6.0</TargetFrameworks>
<OutputPath>../../output/$(Configuration)/TestHelper</OutputPath>
<OutputType>Exe</OutputType>
<RootNamespace>Icu.Tests</RootNamespace>
Expand Down
17 changes: 0 additions & 17 deletions source/icu.net.netstandard.testrunner/Program.cs

This file was deleted.

This file was deleted.

9 changes: 2 additions & 7 deletions source/icu.net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution items", "Solution items", "{ADD2D664-A179-47DE-BE36-94AF75330E29}"
ProjectSection(SolutionItems) = preProject
..\CHANGELOG.md = ..\CHANGELOG.md
.nuget\packages.config = .nuget\packages.config
..\.editorconfig = ..\.editorconfig
..\GitVersion.yml = ..\GitVersion.yml
..\README.md = ..\README.md
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestHelper", "TestHelper\TestHelper.csproj", "{F195ADCE-9129-446E-85E0-8EEAD01ED08D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "icu.net.netstandard.testrunner", "icu.net.netstandard.testrunner\icu.net.netstandard.testrunner.csproj", "{30997039-1AD1-4A11-91EE-F53A41788FB5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,10 +37,6 @@ Global
{F195ADCE-9129-446E-85E0-8EEAD01ED08D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F195ADCE-9129-446E-85E0-8EEAD01ED08D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F195ADCE-9129-446E-85E0-8EEAD01ED08D}.Release|Any CPU.Build.0 = Release|Any CPU
{30997039-1AD1-4A11-91EE-F53A41788FB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30997039-1AD1-4A11-91EE-F53A41788FB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30997039-1AD1-4A11-91EE-F53A41788FB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30997039-1AD1-4A11-91EE-F53A41788FB5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
15 changes: 8 additions & 7 deletions source/icu.net.tests/BreakIteratorTests.JDKCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ namespace Icu.Tests
/// <summary>
/// Tests to ensure compatibility with JDK 7
/// </summary>
// Ignore tests until a JavaBreakIterator using RuleBasedBreakIterator is written. The rules for JavaBreakIterator can be found at:
// http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/text/resources/BreakIteratorRules.java/
// and http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/text/resources/BreakIteratorRules_th.java#BreakIteratorRules_th
[TestFixture]
[Category("Full ICU")]
[Ignore("Ignore tests until a JavaBreakIterator using RuleBasedBreakIterator is written. The rules for JavaBreakIterator can be found at:\n"
+ "http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/text/resources/BreakIteratorRules.java/ \n"
+ "and http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/text/resources/BreakIteratorRules_th.java#BreakIteratorRules_th")]
[Ignore("Needs implementation of JavaBreakIterator using RuleBasedBreakIterator. See comment in code.")]
public class BreakIteratorTests_JDKCompatibility
{
static readonly String TEXT =
Expand All @@ -26,7 +27,7 @@ private BreakIterator GetWordInstance(System.Globalization.CultureInfo locale)
[Test]
public void TestWordIteration()
{
BreakIterator bi = GetWordInstance(System.Globalization.CultureInfo.InvariantCulture);
using var bi = GetWordInstance(System.Globalization.CultureInfo.InvariantCulture);

// Test empty
Assert.AreEqual(0, bi.Current);
Expand Down Expand Up @@ -103,7 +104,7 @@ public void TestWordIteration()
[Test]
public void TestWordIterationThai()
{
BreakIterator bi = GetWordInstance(new System.Globalization.CultureInfo("th"));
using var bi = GetWordInstance(new System.Globalization.CultureInfo("th"));

// Test empty
Assert.AreEqual(0, bi.Current);
Expand Down Expand Up @@ -184,7 +185,7 @@ private BreakIterator GetSentenceInstance(System.Globalization.CultureInfo local
[Test]
public void TestSentenceIteration()
{
BreakIterator bi = GetSentenceInstance(System.Globalization.CultureInfo.InvariantCulture);
using var bi = GetSentenceInstance(System.Globalization.CultureInfo.InvariantCulture);

// Test empty
Assert.AreEqual(0, bi.Current);
Expand Down Expand Up @@ -265,7 +266,7 @@ private BreakIterator GetLineInstance(System.Globalization.CultureInfo locale)
[Test]
public void TestLineIteration()
{
BreakIterator bi = GetLineInstance(System.Globalization.CultureInfo.InvariantCulture);
using var bi = GetLineInstance(System.Globalization.CultureInfo.InvariantCulture);

// Test empty
Assert.AreEqual(0, bi.Current);
Expand Down
4 changes: 2 additions & 2 deletions source/icu.net.tests/Collation/SortKeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void Compare_SamePrefixSecondLonger_precedes()
SortKey sortKey1 = Collator.CreateSortKey("heo", keyData1);
byte[] keyData2 = new byte[] { 0xae, 0x1, 0x20, 0x32, 0x1 };
SortKey sortKey2 = Collator.CreateSortKey("heol", keyData2);
Assert.AreEqual(Precedes, SortKey.Compare(sortKey1, sortKey2));
Assert.That(SortKey.Compare(sortKey1, sortKey2), Is.LessThanOrEqualTo(Precedes));
}

[Test]
Expand All @@ -116,7 +116,7 @@ public void Compare_SamePrefixSecondShorter_follows()
SortKey sortKey1 = Collator.CreateSortKey("heol", keyData1);
byte[] keyData2 = new byte[] { 0xae, 0x1, 0x20, 0x1 };
SortKey sortKey2 = Collator.CreateSortKey("heo", keyData2);
Assert.AreEqual(Follows, SortKey.Compare(sortKey1, sortKey2));
Assert.That(SortKey.Compare(sortKey1, sortKey2), Is.GreaterThanOrEqualTo(Follows));
}


Expand Down
63 changes: 63 additions & 0 deletions source/icu.net.tests/NativeMethods/DllResolverTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2022 SIL International
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)

using System.IO;
using NUnit.Framework;

namespace Icu.Tests
{
#if NET
[TestFixture]
public class DllResolverTests
{
private string _tempPath;

[TearDown]
public void TearDown()
{
if (string.IsNullOrEmpty(_tempPath))
return;

Directory.Delete(_tempPath, true);
_tempPath = null;
}

[TestCase("linux", ExpectedResult = true, IncludePlatform = "Linux")]
[TestCase("Linux", ExpectedResult = true, IncludePlatform = "Linux")]
[TestCase("!windows,osx", ExpectedResult = true, IncludePlatform = "Linux")]
[TestCase("!windows,linux", ExpectedResult = false, IncludePlatform = "Linux, Win")]
[TestCase("windows,linux", ExpectedResult = true, IncludePlatform = "Linux")]
[TestCase("windows", ExpectedResult = true, IncludePlatform = "Win")]
[TestCase("Windows", ExpectedResult = true, IncludePlatform = "Win")]
[TestCase("!linux,osx", ExpectedResult = true, IncludePlatform = "Win")]
[TestCase("windows,linux", ExpectedResult = true, IncludePlatform = "Win")]
[TestCase("osx", ExpectedResult = true, IncludePlatform = "MacOsX")]
[TestCase("OSX", ExpectedResult = true, IncludePlatform = "MacOsX")]
[TestCase("!linux,windows", ExpectedResult = true, IncludePlatform = "MacOsX")]
[TestCase("!windows,osx", ExpectedResult = false, IncludePlatform = "MacOsX, Win")]
[TestCase("windows,osx", ExpectedResult = true, IncludePlatform = "MacOsX")]
public bool ConditionApplies(string condition)
{
return DllResolver.ConditionApplies(condition);
}

[TestCase(ExpectedResult = "libdl.so.2", IncludePlatform = "Linux")]
[TestCase(ExpectedResult = "libdl.dylib", IncludePlatform = "MacOsX")]
[TestCase(ExpectedResult = "libdl.dll", IncludePlatform = "Win")]
public string MapLibraryName()
{
_tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(_tempPath);
var fakeDll = Path.Combine(_tempPath, "test.dll");
var configFile = fakeDll + ".config";
File.WriteAllText(configFile, @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<configuration>
<dllmap os=""!windows,osx"" dll=""libdl.dll"" target=""libdl.so.2"" />
<dllmap os=""osx"" dll=""libdl.dll"" target=""libdl.dylib""/>
</configuration>");

return DllResolver.MapLibraryName(fakeDll, "libdl.dll");
}
}
#endif
}
File renamed without changes.
3 changes: 2 additions & 1 deletion source/icu.net.tests/SetUpFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT)

using System;
using System.Runtime.InteropServices;
using NUnit.Framework;

namespace Icu.Tests
Expand All @@ -15,7 +16,7 @@ private static bool IsWindows
{
// See Icu.Platform. Unfortunately that's internal, so we can't use it.

#if !NETSTANDARD1_6
#if !NETSTANDARD1_6 && !NET
// See http://www.mono-project.com/docs/faq/technical/#how-to-detect-the-execution-platform
switch ((int)Environment.OSVersion.Platform)
{
Expand Down
3 changes: 1 addition & 2 deletions source/icu.net.tests/icu.net.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net461;net6.0</TargetFrameworks>
<RootNamespace>Icu.Tests</RootNamespace>
<AssemblyTitle>icu.net.tests</AssemblyTitle>
<IsPackable>false</IsPackable>
<LangVersion>8</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Icu4c.Win.Full.Lib" Version="62.1.4-beta" />
Expand Down
Loading

0 comments on commit 0ab57ff

Please sign in to comment.