mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 23:01:44 +01:00
Add compile step to all unit tests
This commit is contained in:
parent
233d9b5e84
commit
0f0eff4cd0
@ -12,8 +12,6 @@ namespace CapnpC.CSharp.Generator.Tests
|
||||
[TestClass]
|
||||
public class CodeGeneratorUnitTests
|
||||
{
|
||||
static readonly Dictionary<int, string> GeneratedCode = new Dictionary<int, string>();
|
||||
|
||||
[TestMethod]
|
||||
public void Test00Enumerant()
|
||||
{
|
||||
@ -24,7 +22,7 @@ namespace CapnpC.CSharp.Generator.Tests
|
||||
[TestMethod]
|
||||
public void Test01NestedClash()
|
||||
{
|
||||
var run = LoadAndGenerate("UnitTest1.capnp.bin", 1);
|
||||
var run = LoadAndGenerate("UnitTest1.capnp.bin");
|
||||
var structFoo = GetTypeDef(0x93db6ba5509bac24, run.Model);
|
||||
var names = run.CodeGen.GetNames();
|
||||
var fieldName = names.GetCodeIdentifier(structFoo.Fields[0]).ToString();
|
||||
@ -35,28 +33,25 @@ namespace CapnpC.CSharp.Generator.Tests
|
||||
[TestMethod]
|
||||
public void Test02ForwardInheritance()
|
||||
{
|
||||
LoadAndGenerate("UnitTest2.capnp.bin", 2);
|
||||
// Should not throw
|
||||
LoadAndGenerate("UnitTest2.capnp.bin");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test03NonGeneratedNodeSkip()
|
||||
{
|
||||
LoadAndGenerate("UnitTest3.capnp.bin", 3);
|
||||
// Should not throw
|
||||
LoadAndGenerate("UnitTest3.capnp.bin");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test04MutualDependencies()
|
||||
{
|
||||
LoadAndGenerate("UnitTest4.capnp.bin", 4);
|
||||
// Should not throw
|
||||
LoadAndGenerate("UnitTest4.capnp.bin");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test10ImportedNamespaces()
|
||||
{
|
||||
var run = LoadAndGenerate("UnitTest10.capnp.bin", 10);
|
||||
var run = LoadAndGenerate("UnitTest10.capnp.bin");
|
||||
var outerTypeDef = run.FirstFile.NestedTypes.First();
|
||||
var outerType = Model.Types.FromDefinition(outerTypeDef);
|
||||
var innerType = outerTypeDef.Fields[0].Type;
|
||||
@ -77,22 +72,25 @@ namespace CapnpC.CSharp.Generator.Tests
|
||||
[TestMethod]
|
||||
public void Test11ImportedConst()
|
||||
{
|
||||
LoadAndGenerate("UnitTest11.capnp.bin", 11);
|
||||
// Should not throw
|
||||
LoadAndGenerate("UnitTest11.capnp.bin");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test12ConstEnum()
|
||||
{
|
||||
LoadAndGenerate("UnitTest12.capnp.bin");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test20AnnotationAndConst()
|
||||
{
|
||||
LoadAndGenerate("UnitTest20.capnp.bin", 20);
|
||||
// Should not throw
|
||||
LoadAndGenerate("UnitTest20.capnp.bin");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test30SchemaCapnp()
|
||||
{
|
||||
LoadAndGenerate("schema-with-offsets.capnp.bin");
|
||||
// Should not throw
|
||||
}
|
||||
|
||||
struct Run
|
||||
@ -106,15 +104,14 @@ namespace CapnpC.CSharp.Generator.Tests
|
||||
static CodeGen.CodeGenerator NewGeneratorFor(Model.SchemaModel model)
|
||||
=> new CodeGen.CodeGenerator(model, new CodeGen.GeneratorOptions());
|
||||
|
||||
Run LoadAndGenerate(string inputName, int? testNum = null)
|
||||
Run LoadAndGenerate(string inputName)
|
||||
{
|
||||
var run = new Run();
|
||||
run.Model = Load(inputName);
|
||||
run.CodeGen = NewGeneratorFor(run.Model);
|
||||
run.FirstFile = run.Model.FilesToGenerate.First();
|
||||
run.Code = run.CodeGen.Transform(run.FirstFile);
|
||||
if (testNum is int num)
|
||||
GeneratedCode[num] = run.Code;
|
||||
Assert.IsTrue(Util.InlineAssemblyCompiler.TryCompileCapnp(run.Code), "Compilation was not successful");
|
||||
return run;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,16 @@ namespace CapnpC.CSharp.Generator.Tests.Util
|
||||
{
|
||||
var emitResult = compilation.Emit(stream);
|
||||
|
||||
foreach (var diag in emitResult.Diagnostics)
|
||||
Console.WriteLine($"{diag}");
|
||||
|
||||
if (!emitResult.Success)
|
||||
{
|
||||
string path = Path.ChangeExtension(Path.GetTempFileName(), ".capnp.cs");
|
||||
File.WriteAllText(path, code);
|
||||
Console.WriteLine($"[See {path} for generated code]");
|
||||
}
|
||||
|
||||
return emitResult.Success;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user