mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 14:51:41 +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]
|
[TestClass]
|
||||||
public class CodeGeneratorUnitTests
|
public class CodeGeneratorUnitTests
|
||||||
{
|
{
|
||||||
static readonly Dictionary<int, string> GeneratedCode = new Dictionary<int, string>();
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test00Enumerant()
|
public void Test00Enumerant()
|
||||||
{
|
{
|
||||||
@ -24,7 +22,7 @@ namespace CapnpC.CSharp.Generator.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test01NestedClash()
|
public void Test01NestedClash()
|
||||||
{
|
{
|
||||||
var run = LoadAndGenerate("UnitTest1.capnp.bin", 1);
|
var run = LoadAndGenerate("UnitTest1.capnp.bin");
|
||||||
var structFoo = GetTypeDef(0x93db6ba5509bac24, run.Model);
|
var structFoo = GetTypeDef(0x93db6ba5509bac24, run.Model);
|
||||||
var names = run.CodeGen.GetNames();
|
var names = run.CodeGen.GetNames();
|
||||||
var fieldName = names.GetCodeIdentifier(structFoo.Fields[0]).ToString();
|
var fieldName = names.GetCodeIdentifier(structFoo.Fields[0]).ToString();
|
||||||
@ -35,28 +33,25 @@ namespace CapnpC.CSharp.Generator.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test02ForwardInheritance()
|
public void Test02ForwardInheritance()
|
||||||
{
|
{
|
||||||
LoadAndGenerate("UnitTest2.capnp.bin", 2);
|
LoadAndGenerate("UnitTest2.capnp.bin");
|
||||||
// Should not throw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test03NonGeneratedNodeSkip()
|
public void Test03NonGeneratedNodeSkip()
|
||||||
{
|
{
|
||||||
LoadAndGenerate("UnitTest3.capnp.bin", 3);
|
LoadAndGenerate("UnitTest3.capnp.bin");
|
||||||
// Should not throw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test04MutualDependencies()
|
public void Test04MutualDependencies()
|
||||||
{
|
{
|
||||||
LoadAndGenerate("UnitTest4.capnp.bin", 4);
|
LoadAndGenerate("UnitTest4.capnp.bin");
|
||||||
// Should not throw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test10ImportedNamespaces()
|
public void Test10ImportedNamespaces()
|
||||||
{
|
{
|
||||||
var run = LoadAndGenerate("UnitTest10.capnp.bin", 10);
|
var run = LoadAndGenerate("UnitTest10.capnp.bin");
|
||||||
var outerTypeDef = run.FirstFile.NestedTypes.First();
|
var outerTypeDef = run.FirstFile.NestedTypes.First();
|
||||||
var outerType = Model.Types.FromDefinition(outerTypeDef);
|
var outerType = Model.Types.FromDefinition(outerTypeDef);
|
||||||
var innerType = outerTypeDef.Fields[0].Type;
|
var innerType = outerTypeDef.Fields[0].Type;
|
||||||
@ -77,22 +72,25 @@ namespace CapnpC.CSharp.Generator.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test11ImportedConst()
|
public void Test11ImportedConst()
|
||||||
{
|
{
|
||||||
LoadAndGenerate("UnitTest11.capnp.bin", 11);
|
LoadAndGenerate("UnitTest11.capnp.bin");
|
||||||
// Should not throw
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Test12ConstEnum()
|
||||||
|
{
|
||||||
|
LoadAndGenerate("UnitTest12.capnp.bin");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test20AnnotationAndConst()
|
public void Test20AnnotationAndConst()
|
||||||
{
|
{
|
||||||
LoadAndGenerate("UnitTest20.capnp.bin", 20);
|
LoadAndGenerate("UnitTest20.capnp.bin");
|
||||||
// Should not throw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Test30SchemaCapnp()
|
public void Test30SchemaCapnp()
|
||||||
{
|
{
|
||||||
LoadAndGenerate("schema-with-offsets.capnp.bin");
|
LoadAndGenerate("schema-with-offsets.capnp.bin");
|
||||||
// Should not throw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Run
|
struct Run
|
||||||
@ -106,15 +104,14 @@ namespace CapnpC.CSharp.Generator.Tests
|
|||||||
static CodeGen.CodeGenerator NewGeneratorFor(Model.SchemaModel model)
|
static CodeGen.CodeGenerator NewGeneratorFor(Model.SchemaModel model)
|
||||||
=> new CodeGen.CodeGenerator(model, new CodeGen.GeneratorOptions());
|
=> new CodeGen.CodeGenerator(model, new CodeGen.GeneratorOptions());
|
||||||
|
|
||||||
Run LoadAndGenerate(string inputName, int? testNum = null)
|
Run LoadAndGenerate(string inputName)
|
||||||
{
|
{
|
||||||
var run = new Run();
|
var run = new Run();
|
||||||
run.Model = Load(inputName);
|
run.Model = Load(inputName);
|
||||||
run.CodeGen = NewGeneratorFor(run.Model);
|
run.CodeGen = NewGeneratorFor(run.Model);
|
||||||
run.FirstFile = run.Model.FilesToGenerate.First();
|
run.FirstFile = run.Model.FilesToGenerate.First();
|
||||||
run.Code = run.CodeGen.Transform(run.FirstFile);
|
run.Code = run.CodeGen.Transform(run.FirstFile);
|
||||||
if (testNum is int num)
|
Assert.IsTrue(Util.InlineAssemblyCompiler.TryCompileCapnp(run.Code), "Compilation was not successful");
|
||||||
GeneratedCode[num] = run.Code;
|
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,16 @@ namespace CapnpC.CSharp.Generator.Tests.Util
|
|||||||
{
|
{
|
||||||
var emitResult = compilation.Emit(stream);
|
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;
|
return emitResult.Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user