Skip to content

Commit c2395c2

Browse files
jonpryorgrendello
authored andcommitted
[generator-Tests] Provide more context when errors happen (#48)
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.)
1 parent 6fc9c69 commit c2395c2

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

tools/generator/Tests/BaseGeneratorTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ public void Execute ()
3838
if (output.Contains ("error")) {
3939
Assert.Fail (output);
4040
}
41-
string[] errors;
42-
BuiltAssembly = Compiler.Compile (Options, "Mono.Andoroid",
43-
AdditionalSourceDirectories, out errors);
44-
Assert.AreEqual (0, errors.Length, string.Join (Environment.NewLine, errors));
41+
bool hasErrors;
42+
string compilerOutput;
43+
BuiltAssembly = Compiler.Compile (Options, "Mono.Andoroid", AdditionalSourceDirectories,
44+
out hasErrors, out compilerOutput);
45+
Assert.AreEqual (false, hasErrors, compilerOutput);
4546
Assert.IsNotNull (BuiltAssembly);
4647
}
4748

tools/generator/Tests/Compiler.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public static class Compiler
1717
private static string supportFilePath = typeof(Compiler).Assembly.Location;
1818

1919
public static Assembly Compile (Xamarin.Android.Binder.CodeGeneratorOptions options,
20-
string assemblyFileName, IEnumerable<string> AdditionalSourceDirectories, out string[] errors)
20+
string assemblyFileName, IEnumerable<string> AdditionalSourceDirectories,
21+
out bool hasErrors, out string output)
2122
{
2223
var generatedCodePath = options.ManagedCallableWrapperSourceOutputDirectory;
2324
var sourceFiles = Directory.EnumerateFiles (generatedCodePath, "*.cs",
@@ -53,14 +54,12 @@ public static Assembly Compile (Xamarin.Android.Binder.CodeGeneratorOptions opti
5354
CSharpCodeProvider codeProvider = new CSharpCodeProvider ();
5455
CompilerResults results = codeProvider.CompileAssemblyFromFile (parameters,sourceFiles.ToArray ());
5556

56-
List<string> errs = new List<string> ();
57+
hasErrors = false;
58+
5759
foreach (CompilerError message in results.Errors) {
58-
if (message.IsWarning)
59-
continue;
60-
errs.Add (message.ToString ());
60+
hasErrors = hasErrors || (!message.IsWarning);
6161
}
62-
63-
errors = errs.ToArray ();
62+
output = string.Join (Environment.NewLine, results.Output.Cast<string> ());
6463

6564
return results.CompiledAssembly;
6665
}

0 commit comments

Comments
 (0)