From db4a11f123f9f405af54a25b78c204984dae4a10 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 22 Jun 2016 14:29:00 -0400 Subject: [PATCH] [generator-Tests] Provide more context when errors happen A unit test failure is being reported, which unfortunately doesn't contain enough useful context: 1) generatortests.NormalMethods.GeneratedOK : error : .../Java.Interop/bin/TestDebug/SupportFiles/JavaObject.cs(78,17): (Location of the symbol related to previous warning) Expected: 0 But was: 1 It's a very odd "error", in that there's no error reported, just a mention of a "previous warning", which isn't shown. The *cause* of this useless output is that `Compiler` "trims out" all the "non-error" output from the compilation. This *seems* good, except in this case it's the "useless output" that we need to make sense of anything at all! Revise `Compiler.Compile()` so that instead of extracting "errors" it instead provides *all* compiler output and an indicator of whether or not errors occurred. (This still depends on `CompilerResults.Errors` having correct output -- and I'm starting to wonder if I'm actually dealing with a CodeDom bug here -- but at least with more output I can better rationalize about what's going on.) --- tools/generator/Tests/BaseGeneratorTest.cs | 9 +++++---- tools/generator/Tests/Compiler.cs | 13 ++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/generator/Tests/BaseGeneratorTest.cs b/tools/generator/Tests/BaseGeneratorTest.cs index 7a28206c7..231b2b361 100644 --- a/tools/generator/Tests/BaseGeneratorTest.cs +++ b/tools/generator/Tests/BaseGeneratorTest.cs @@ -38,10 +38,11 @@ public void Execute () if (output.Contains ("error")) { Assert.Fail (output); } - string[] errors; - BuiltAssembly = Compiler.Compile (Options, "Mono.Andoroid", - AdditionalSourceDirectories, out errors); - Assert.AreEqual (0, errors.Length, string.Join (Environment.NewLine, errors)); + bool hasErrors; + string compilerOutput; + BuiltAssembly = Compiler.Compile (Options, "Mono.Andoroid", AdditionalSourceDirectories, + out hasErrors, out compilerOutput); + Assert.AreEqual (false, hasErrors, compilerOutput); Assert.IsNotNull (BuiltAssembly); } diff --git a/tools/generator/Tests/Compiler.cs b/tools/generator/Tests/Compiler.cs index ca5dfd7f7..b32445040 100644 --- a/tools/generator/Tests/Compiler.cs +++ b/tools/generator/Tests/Compiler.cs @@ -17,7 +17,8 @@ public static class Compiler private static string supportFilePath = typeof(Compiler).Assembly.Location; public static Assembly Compile (Xamarin.Android.Binder.CodeGeneratorOptions options, - string assemblyFileName, IEnumerable AdditionalSourceDirectories, out string[] errors) + string assemblyFileName, IEnumerable AdditionalSourceDirectories, + out bool hasErrors, out string output) { var generatedCodePath = options.ManagedCallableWrapperSourceOutputDirectory; var sourceFiles = Directory.EnumerateFiles (generatedCodePath, "*.cs", @@ -53,14 +54,12 @@ public static Assembly Compile (Xamarin.Android.Binder.CodeGeneratorOptions opti CSharpCodeProvider codeProvider = new CSharpCodeProvider (); CompilerResults results = codeProvider.CompileAssemblyFromFile (parameters,sourceFiles.ToArray ()); - List errs = new List (); + hasErrors = false; + foreach (CompilerError message in results.Errors) { - if (message.IsWarning) - continue; - errs.Add (message.ToString ()); + hasErrors = hasErrors || (!message.IsWarning); } - - errors = errs.ToArray (); + output = string.Join (Environment.NewLine, results.Output.Cast ()); return results.CompiledAssembly; }