Skip to content

Commit 4d5d2ff

Browse files
jonathanpeppersjonpryor
authored andcommitted
[tests] various fixes for Windows (#192)
`Java.Interop.sln` did not compile on Windows: - `Java.Runtime.Environment.dll.config` can be conditional, I don't think it is needed on Windows - `Bytecode-Tests.csproj` needs to use `$(JavaCPath)` instead of `javac` `generator-Tests` were not passing: - `BaseGeneratorTest` needs to ignore line endings when comparing files - also fixed a typo - `Compiler` was not able to locate `System.Runtime.dll` on Windows. It turns out there is not a `Facades` directory on Windows (just a flat directory), so added a `Directory.Exists()` check
1 parent 1865534 commit 4d5d2ff

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

src/Java.Runtime.Environment/Java.Runtime.Environment.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</ProjectReference>
4949
</ItemGroup>
5050
<ItemGroup>
51-
<Content Include="Java.Runtime.Environment.dll.config">
51+
<Content Include="Java.Runtime.Environment.dll.config" Condition=" '$(OS)' != 'Windows_NT' ">
5252
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5353
</Content>
5454
</ItemGroup>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\..\Configuration.props" />
34
<PropertyGroup>
45
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
56
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -73,8 +74,8 @@
7374
</PropertyGroup>
7475
<Target Name="BuildClasses" Inputs="@(TestJar)" Outputs="@(TestJar-&gt;'$(IntermediateOutputPath)classes\%(RecursiveDir)%(Filename).class')">
7576
<MakeDir Directories="$(IntermediateOutputPath)classes" />
76-
<Exec Command="&quot;javac&quot; -parameters -source 1.5 -target 1.6 -g -d &quot;$(IntermediateOutputPath)classes&quot; @(TestJar->'%(Identity)', ' ')" />
77-
<Exec Command="&quot;javac&quot; -source 1.5 -target 1.6 -g -d &quot;$(IntermediateOutputPath)classes&quot; @(TestJarNoParameters->'%(Identity)', ' ')" />
77+
<Exec Command="&quot;$(JavaCPath)&quot; -parameters -source 1.5 -target 1.6 -g -d &quot;$(IntermediateOutputPath)classes&quot; @(TestJar->'%(Identity)', ' ')" />
78+
<Exec Command="&quot;$(JavaCPath)&quot; -source 1.5 -target 1.6 -g -d &quot;$(IntermediateOutputPath)classes&quot; @(TestJarNoParameters->'%(Identity)', ' ')" />
7879
</Target>
7980
<ItemGroup>
8081
<ProjectReference Include="..\Xamarin.Android.Tools.Bytecode.csproj">

tools/generator/Tests/BaseGeneratorTest.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void Execute ()
4040
}
4141
bool hasErrors;
4242
string compilerOutput;
43-
BuiltAssembly = Compiler.Compile (Options, "Mono.Andoroid", AdditionalSourceDirectories,
43+
BuiltAssembly = Compiler.Compile (Options, "Mono.Android", AdditionalSourceDirectories,
4444
out hasErrors, out compilerOutput);
4545
Assert.AreEqual (false, hasErrors, compilerOutput);
4646
Assert.IsNotNull (BuiltAssembly);
@@ -79,8 +79,8 @@ protected bool FileCompare (string file1, string file2)
7979
result = File.Exists (file1) && File.Exists (file2);
8080

8181
if (result) {
82-
byte[] f1 = File.ReadAllBytes (file1);
83-
byte[] f2 = File.ReadAllBytes (file2);
82+
byte[] f1 = ReadAllBytesIgnoringLineEndings (file1);
83+
byte[] f2 = ReadAllBytesIgnoringLineEndings (file2);
8484

8585
var hash = MD5.Create ();
8686
var f1hash = Convert.ToBase64String (hash.ComputeHash (f1));
@@ -91,6 +91,22 @@ protected bool FileCompare (string file1, string file2)
9191
return result;
9292
}
9393

94+
private byte[] ReadAllBytesIgnoringLineEndings (string path)
95+
{
96+
using (var memoryStream = new MemoryStream ()) {
97+
using (var file = File.OpenRead (path)) {
98+
int readByte;
99+
while ((readByte = file.ReadByte()) != -1) {
100+
byte b = (byte)readByte;
101+
if (b != '\r' && b != '\n') {
102+
memoryStream.WriteByte (b);
103+
}
104+
}
105+
}
106+
return memoryStream.ToArray ();
107+
}
108+
}
109+
94110
protected void RunAllTargets (string outputRelativePath, string apiDescriptionFile, string expectedRelativePath, string[] additionalSupportPaths = null)
95111
{
96112
Run (CodeGenerationTarget.XamarinAndroid, Path.Combine ("out", outputRelativePath), apiDescriptionFile, Path.Combine ("expected", expectedRelativePath), additionalSupportPaths);

tools/generator/Tests/Compiler.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ static string GetFacadesPath ()
7070
var env = Environment.GetEnvironmentVariable ("FACADES_PATH");
7171
if (env != null)
7272
return env;
73-
return Path.Combine (
74-
Path.GetDirectoryName (typeof (object).Assembly.Location),
75-
"Facades");
73+
74+
var dir = Path.GetDirectoryName (typeof (object).Assembly.Location);
75+
var facades = Path.Combine (dir, "Facades");
76+
if (Directory.Exists (facades))
77+
return facades;
78+
79+
return dir;
7680
}
7781
}
7882
}

0 commit comments

Comments
 (0)