Skip to content

[generator-Tests] Provide more context when errors happen #48

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tools/generator/Tests/BaseGeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 6 additions & 7 deletions tools/generator/Tests/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> AdditionalSourceDirectories, out string[] errors)
string assemblyFileName, IEnumerable<string> AdditionalSourceDirectories,
out bool hasErrors, out string output)
{
var generatedCodePath = options.ManagedCallableWrapperSourceOutputDirectory;
var sourceFiles = Directory.EnumerateFiles (generatedCodePath, "*.cs",
Expand Down Expand Up @@ -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<string> errs = new List<string> ();
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<string> ());

return results.CompiledAssembly;
}
Expand Down