Skip to content

Commit 41ba348

Browse files
authored
[tests] Add net6.0 TargetFramework. (#888)
Today, even when building and testing on .NET 6, most of our test suites are still building and running with `net472`. Fix this by adding `net6.0` to `$(TargetFrameworks)` and updating CI to run the `net6.0` version instead of the `net472` version. Fixes were required to account for differences between `net472` and `net6.0` behavior, in particular: * The semantics for the [Round-trip format specifier `R`][0] changed between .NET Framework and .NET 6. Update `ConstantPoolFloatItem.ToString()` and `ConstantPoolDoubleItem.ToString()` to use the G9 and G17 format specifiers, respectively, so that behavior is consistent. * Types such as `System.String` moved from `mscorlib.dll` to `System.Private.CoreLib.dll`, which impacts the output of `JavaNativeTypeManager.GetPackageName()`, as the assembly name is taken into consideration. Assertions around `JavaNativeTypeManager.GetPackageName()` need to be based on the target framework. * When using `CSharpCompilation.Create()`, `System.Runtime.dll` must now be referenced when building on net6+, otherwise certain types won't be resolved: error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (SourceFile([871..891))) error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (SourceFile([944..962))) error CS0012: The type 'IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (SourceFile([312..321))) * `MarshalMemberBuilderTest.cs` must be disabled when building for .NET 6+, as `AssemblyBuilderAccess.Save` doesn't exist, nor does `AppDomain.DefineDynamicAssembly()`, nor `LambdaExpression.CompileToMethod()`. Related: #616 error CS0117: 'AssemblyBuilderAccess' does not contain a definition for 'Save' error CS1061: 'AppDomain' does not contain a definition for 'DefineDynamicAssembly' and no accessible extension method 'DefineDynamicAssembly' accepting a first argument of type 'AppDomain' could be found (are you missing a using directive or an assembly reference?) error CS1061: 'LambdaExpression' does not contain a definition for 'CompileToMethod' and no accessible extension method 'CompileToMethod' accepting a first argument of type 'LambdaExpression' could be found (are you missing a using directive or an assembly reference?) [0]: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#round-trip-format-specifier-r
1 parent 403dd37 commit 41ba348

File tree

18 files changed

+48
-32
lines changed

18 files changed

+48
-32
lines changed

build-tools/automation/templates/core-tests.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,56 @@ steps:
77
displayName: 'Tests: generator'
88
inputs:
99
command: test
10-
arguments: bin/Test$(Build.Configuration)/generator-Tests.dll
10+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/generator-Tests.dll
1111
continueOnError: true
1212

1313
- task: DotNetCoreCLI@2
1414
displayName: 'Tests: JavaCallableWrappers'
1515
inputs:
1616
command: test
17-
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.JavaCallableWrappers-Tests.dll
17+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Interop.Tools.JavaCallableWrappers-Tests.dll
1818
continueOnError: true
1919

2020
- task: DotNetCoreCLI@2
2121
displayName: 'Tests: logcat-parse'
2222
inputs:
2323
command: test
24-
arguments: bin/Test$(Build.Configuration)/logcat-parse-Tests.dll
24+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/logcat-parse-Tests.dll
2525
continueOnError: true
2626

2727
- task: DotNetCoreCLI@2
2828
displayName: 'Tests: ApiXmlAdjuster'
2929
inputs:
3030
command: test
31-
arguments: bin/Test$(Build.Configuration)/Xamarin.Android.Tools.ApiXmlAdjuster-Tests.dll
31+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Xamarin.Android.Tools.ApiXmlAdjuster-Tests.dll
3232
continueOnError: true
3333

3434
- task: DotNetCoreCLI@2
3535
displayName: 'Tests: Bytecode'
3636
inputs:
3737
command: test
38-
arguments: bin/Test$(Build.Configuration)/Xamarin.Android.Tools.Bytecode-Tests.dll
38+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Xamarin.Android.Tools.Bytecode-Tests.dll
3939
continueOnError: true
4040

4141
- task: DotNetCoreCLI@2
4242
displayName: 'Tests: Java.Interop.Tools.Generator'
4343
inputs:
4444
command: test
45-
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.Generator-Tests.dll
45+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Interop.Tools.Generator-Tests.dll
4646
continueOnError: true
4747

4848
- task: DotNetCoreCLI@2
4949
displayName: 'Tests: Java.Interop.Tools.JavaSource'
5050
inputs:
5151
command: test
52-
arguments: bin/Test$(Build.Configuration)/Java.Interop.Tools.JavaSource-Tests.dll
52+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Interop.Tools.JavaSource-Tests.dll
5353
continueOnError: true
5454

5555
- task: DotNetCoreCLI@2
5656
displayName: 'Tests: Xamarin.SourceWriter'
5757
inputs:
5858
command: test
59-
arguments: bin/Test$(Build.Configuration)/Xamarin.SourceWriter-Tests.dll
59+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Xamarin.SourceWriter-Tests.dll
6060
continueOnError: true
6161

6262
- task: DotNetCoreCLI@2
@@ -80,15 +80,15 @@ steps:
8080
condition: eq('${{ parameters.runNativeTests }}', 'true')
8181
inputs:
8282
command: test
83-
arguments: bin/Test$(Build.Configuration)/Java.Interop.Dynamic-Tests.dll
83+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Interop.Dynamic-Tests.dll
8484
continueOnError: true
8585

8686
- task: DotNetCoreCLI@2
8787
displayName: 'Tests: Java.Interop.Export'
8888
condition: eq('${{ parameters.runNativeTests }}', 'true')
8989
inputs:
9090
command: test
91-
arguments: bin/Test$(Build.Configuration)/Java.Interop.Export-Tests.dll
91+
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Interop.Export-Tests.dll
9292
continueOnError: true
9393

9494
- task: DotNetCoreCLI@2

src/Xamarin.Android.Tools.Bytecode/ConstantPool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public float Value {
266266

267267
public override string ToString ()
268268
{
269-
return string.Format (CultureInfo.InvariantCulture, "Float({0})", Value);
269+
return string.Format (CultureInfo.InvariantCulture, "Float({0:G9})", Value);
270270
}
271271
}
272272

@@ -335,7 +335,7 @@ public double Value {
335335

336336
public override string ToString ()
337337
{
338-
return string.Format (CultureInfo.InvariantCulture, "Double({0})", Value);
338+
return string.Format (CultureInfo.InvariantCulture, "Double({0:G17})", Value);
339339
}
340340
}
341341

src/Xamarin.Android.Tools.Bytecode/XmlClassDeclarationBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ static XAttribute GetValue (FieldInfo field)
529529
else if (Double.IsPositiveInfinity (doubleItem.Value))
530530
value = "(1.0 / 0.0)";
531531
else
532-
value = doubleItem.Value.ToString ("R", CultureInfo.InvariantCulture);
532+
value = doubleItem.Value.ToString ("G17", CultureInfo.InvariantCulture);
533533
break;
534534
case ConstantPoolItemType.Float:
535535
var floatItem = (ConstantPoolFloatItem) constant;
@@ -540,7 +540,7 @@ static XAttribute GetValue (FieldInfo field)
540540
else if (Double.IsPositiveInfinity (floatItem.Value))
541541
value = "(1.0f / 0.0f)";
542542
else
543-
value = floatItem.Value.ToString ("R", CultureInfo.InvariantCulture);
543+
value = floatItem.Value.ToString ("G9", CultureInfo.InvariantCulture);
544544
break;
545545
case ConstantPoolItemType.Long: value = ((ConstantPoolLongItem) constant).Value.ToString (); break;
546546
case ConstantPoolItemType.Integer:

tests/Java.Interop.Dynamic-Tests/Java.Interop.Dynamic-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
</PropertyGroup>

tests/Java.Interop.Export-Tests/Java.Interop.Export-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
</PropertyGroup>

tests/Java.Interop.Export-Tests/Java.Interop/MarshalMemberBuilderTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Java.InteropTests
1414
{
15+
#if !NET
1516
[TestFixture]
1617
class MarshalMemberBuilderTest : JavaVMFixture
1718
{
@@ -555,4 +556,5 @@ public void CreateConstructActivationPeerExpression ()
555556
}}");
556557
}
557558
}
559+
#endif // !NET
558560
}

tests/Java.Interop.Tools.Generator-Tests/Java.Interop.Tools.Generator-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<RootNamespace>Java.Interop.Tools.Common_Tests</RootNamespace>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<DefineConstants>$(DefineConstants);HAVE_CECIL;JCW_ONLY_TYPE_NAMES</DefineConstants>
77
</PropertyGroup>

tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers/JavaNativeTypeManagerTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ public void TearDown ()
2929
public void Crc64 ()
3030
{
3131
JavaNativeTypeManager.PackageNamingPolicy = PackageNamingPolicy.LowercaseCrc64;
32+
#if NET
33+
// System.String moved assemblies in .NET
34+
Assert.AreEqual ("crc64d04135c992393d83", JavaNativeTypeManager.GetPackageName (typeof (string)));
35+
#else // !NET
3236
Assert.AreEqual ("crc64b74743e9328eed0a", JavaNativeTypeManager.GetPackageName (typeof (string)));
37+
#endif // !NET
3338
}
3439

3540
[Test]
@@ -43,7 +48,12 @@ public void Lowercase ()
4348
public void LowercaseWithAssemblyName ()
4449
{
4550
JavaNativeTypeManager.PackageNamingPolicy = PackageNamingPolicy.LowercaseWithAssemblyName;
51+
#if NET
52+
// System.String moved assemblies in .NET
53+
Assert.AreEqual ("assembly_system_private_corelib.system", JavaNativeTypeManager.GetPackageName (typeof (string)));
54+
#else // !NET
4655
Assert.AreEqual ("assembly_mscorlib.system", JavaNativeTypeManager.GetPackageName (typeof (string)));
56+
#endif // !NET
4757
}
4858
}
4959
}

tests/Java.Interop.Tools.JavaSource-Tests/Java.Interop.Tools.JavaSource-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net472</TargetFramework>
3+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
44
<IsPackable>False</IsPackable>
55
</PropertyGroup>
66
<PropertyGroup>

tests/Xamarin.Android.Tools.ApiXmlAdjuster-Tests/Xamarin.Android.Tools.ApiXmlAdjuster-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

tests/Xamarin.Android.Tools.Bytecode-Tests/JavaTypeTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44

@@ -114,25 +114,25 @@ public void ClassFile_WithJavaType_class ()
114114
Name = "STATIC_FINAL_SINGLE_MIN",
115115
Descriptor = "F",
116116
AccessFlags = FieldAccessFlags.Public | FieldAccessFlags.Static | FieldAccessFlags.Final,
117-
ConstantValue = "Float(1.401298E-45)",
117+
ConstantValue = "Float(1.40129846E-45)",
118118
},
119119
new ExpectedFieldDeclaration {
120120
Name = "STATIC_FINAL_SINGLE_MAX",
121121
Descriptor = "F",
122122
AccessFlags = FieldAccessFlags.Public | FieldAccessFlags.Static | FieldAccessFlags.Final,
123-
ConstantValue = "Float(3.402823E+38)",
123+
ConstantValue = "Float(3.40282347E+38)",
124124
},
125125
new ExpectedFieldDeclaration {
126126
Name = "STATIC_FINAL_DOUBLE_MIN",
127127
Descriptor = "D",
128128
AccessFlags = FieldAccessFlags.Public | FieldAccessFlags.Static | FieldAccessFlags.Final,
129-
ConstantValue = "Double(4.94065645841247E-324)",
129+
ConstantValue = "Double(4.9406564584124654E-324)",
130130
},
131131
new ExpectedFieldDeclaration {
132132
Name = "STATIC_FINAL_DOUBLE_MAX",
133133
Descriptor = "D",
134134
AccessFlags = FieldAccessFlags.Public | FieldAccessFlags.Static | FieldAccessFlags.Final,
135-
ConstantValue = "Double(1.79769313486232E+308)",
135+
ConstantValue = "Double(1.7976931348623157E+308)",
136136
},
137137
new ExpectedFieldDeclaration {
138138
Name = "STATIC_FINAL_STRING",

tests/Xamarin.Android.Tools.Bytecode-Tests/Resources/JavaType.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@
490490
type="double"
491491
type-generic-aware="double"
492492
jni-signature="D"
493-
value="4.94065645841247E-324"
493+
value="4.9406564584124654E-324"
494494
visibility="public"
495495
volatile="false" />
496496
<field
@@ -593,7 +593,7 @@
593593
type="float"
594594
type-generic-aware="float"
595595
jni-signature="F"
596-
value="1.401298E-45"
596+
value="1.40129846E-45"
597597
visibility="public"
598598
volatile="false" />
599599
<field

tests/Xamarin.Android.Tools.Bytecode-Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

tests/Xamarin.SourceWriter-Tests/Xamarin.SourceWriter-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

tests/generator-Tests/Integration-Tests/Compiler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ public static Assembly Compile (Xamarin.Android.Binder.CodeGeneratorOptions opti
4747
MetadataReference.CreateFromFile (typeof(Enumerable).Assembly.Location),
4848
MetadataReference.CreateFromFile (typeof(Uri).Assembly.Location),
4949
MetadataReference.CreateFromFile (Path.Combine (binDir, "Java.Interop.dll")),
50-
MetadataReference.CreateFromFile (Path.Combine (facDir, "netstandard.dll"))
50+
MetadataReference.CreateFromFile (Path.Combine (facDir, "netstandard.dll")),
51+
#if NET
52+
MetadataReference.CreateFromFile (Path.Combine (facDir, "System.Runtime.dll")),
53+
#endif // NET
5154
};
5255

56+
5357
// Compile!
5458
var compilation = CSharpCompilation.Create (
5559
Path.GetFileName (assemblyFileName),

tests/generator-Tests/generator-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
</PropertyGroup>

tests/logcat-parse-Tests/logcat-parse-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

0 commit comments

Comments
 (0)