Skip to content

Commit

Permalink
Capture console in tests (#497)
Browse files Browse the repository at this point in the history
* Capture console output in tests using z80dotnet
Use console in GenericField tests to report failures

* Tidy up test runner

* Tidy up tests to use Eval and console output
Fix issue with copying data for empty structs which are padded to 1 byte
Uncomment generic type parameters tests previously failing due to empty structs padded to 1 byte

* Remove ByRef changes accidentally committed

* Fix SQ issues

* Nullable type fixes
  • Loading branch information
drcjt authored Jun 30, 2024
1 parent 2f5ac68 commit b356312
Show file tree
Hide file tree
Showing 25 changed files with 499 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void GenerateCode(LocalVariableEntry entry, CodeGeneratorContext context)
var variable = context.LocalVariableTable[entry.LocalNumber];
var size = variable.ExactSize;

if (variable.Type.IsSmall())
if (variable.Type.IsSmall() || (variable.Type == VarType.Struct && size == 1))
{
CopyHelper.CopySmallFromIXToStack(context.InstructionsBuilder, variable.Type.IsByte() ? 1 : 2, -variable.StackOffset, !variable.Type.IsUnsigned());
}
Expand Down
2 changes: 1 addition & 1 deletion ILCompiler/Compiler/Z80AssemblyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private ushort GetOrgAddress()
{
if (_configuration.IntegrationTests)
{
return 0x0000;
return 0x0050;
}
return _configuration.TargetArchitecture switch
{
Expand Down
2 changes: 2 additions & 0 deletions ILCompiler/TypeSystem/Common/InstantiatedType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ public override IEnumerable<FieldDesc> GetFields()
public override VarType VarType => _typeDef.VarType;

public override string Name => _typeDef.Name;

public override bool IsValueType => _typeDef.IsValueType;
}
}
27 changes: 21 additions & 6 deletions Tests/Generics/GenericFields/InstanceAssignmentClass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GenericFields
using System;

namespace GenericFields
{
internal class InstanceAssignmentClass
{
Expand All @@ -13,18 +15,31 @@ public T Assign(T t)
}
}

public static int RunTests()
private static int _counter = 0;
private static bool _result = true;
public static void Eval(bool exp)
{
_counter++;
if (!exp)
{
_result = exp;
Console.Write("InstanceAssignmentClass failed at location: ");
Console.WriteLine(_counter);
}
}

public static bool RunTests()
{
int _int = 1;
if (new Gen<int>().Assign(_int) != _int) return 1;
Eval(new Gen<int>().Assign(_int) == _int);

string _string = "string";
if (new Gen<string>().Assign(_string) != _string) return 2;
Eval(new Gen<string>().Assign(_string) == _string);

var _object = new object();
if (new Gen<object>().Assign(_object) != _object) return 3;
Eval(new Gen<object>().Assign(_object) == _object);

return 0;
return _result;
}
}
}
27 changes: 21 additions & 6 deletions Tests/Generics/GenericFields/InstanceAssignmentStruct.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GenericFields
using System;

namespace GenericFields
{
internal class InstanceAssignmentStruct
{
Expand All @@ -13,18 +15,31 @@ public T Assign(T t)
}
}

public static int RunTests()
private static int _counter = 0;
private static bool _result = true;
public static void Eval(bool exp)
{
_counter++;
if (!exp)
{
_result = exp;
Console.Write("InstanceAssignmentStruct failed at location: ");
Console.WriteLine(_counter);
}
}

public static bool RunTests()
{
int _int = 1;
if (new Gen<int>().Assign(_int) != _int) return 1;
Eval(new Gen<int>().Assign(_int) == _int);

string _string = "string";
if (new Gen<string>().Assign(_string) != _string) return 2;
Eval(new Gen<string>().Assign(_string) == _string);

var _object = new object();
if (new Gen<object>().Assign(_object) != _object) return 3;
Eval(new Gen<object>().Assign(_object) == _object);

return 0;
return _result;
}
}
}
35 changes: 25 additions & 10 deletions Tests/Generics/GenericFields/InstanceEqualNullClass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GenericFields
using System;

namespace GenericFields
{
internal class InstanceEqualNullClass
{
Expand All @@ -9,24 +11,37 @@ public class Gen<T>
public bool EqualNull(T? t)
{
Field1 = t;
return ((object)Field1! == null);
return ((object?)Field1 == null);
}
}

private static int _counter = 0;
private static bool _result = true;
public static void Eval(bool exp)
{
_counter++;
if (!exp)
{
_result = exp;
Console.Write("InstanceEqualNullClass failed at location: ");
Console.WriteLine(_counter);
}
}

public static int RunTests()
public static bool RunTests()
{
int _int = 1;
if (new Gen<int>().EqualNull(_int)) return 1;
Eval(!new Gen<int>().EqualNull(_int));

string _string = "string";
if (new Gen<string>().EqualNull(_string)) return 2;
if (!new Gen<string>().EqualNull(null)) return 3;
string _string = "string";
Eval(!new Gen<string>().EqualNull(_string));
Eval(new Gen<string>().EqualNull(null));

var _object = new object();
if (new Gen<object>().EqualNull(_object)) return 4;
if (!new Gen<object>().EqualNull(null)) return 5;
Eval(!new Gen<object>().EqualNull(_object));
Eval(new Gen<object>().EqualNull(null));

return 0;
return _result;
}
}
}
33 changes: 24 additions & 9 deletions Tests/Generics/GenericFields/InstanceEqualNullStruct.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GenericFields
using System;

namespace GenericFields
{
internal class InstanceEqualNullStruct
{
Expand All @@ -9,24 +11,37 @@ public struct Gen<T>
public bool EqualNull(T? t)
{
Field1 = t;
return ((object)Field1! == null);
return ((object?)Field1 == null);
}
}

private static int _counter = 0;
private static bool _result = true;
public static void Eval(bool exp)
{
_counter++;
if (!exp)
{
_result = exp;
Console.Write("InstanceEqualNullStruct failed at location: ");
Console.WriteLine(_counter);
}
}

public static int RunTests()
public static bool RunTests()
{
int _int = 1;
if (new Gen<int>().EqualNull(_int)) return 1;
Eval(!new Gen<int>().EqualNull(_int));

string _string = "string";
if (new Gen<string>().EqualNull(_string)) return 2;
if (!new Gen<string>().EqualNull(null)) return 3;
Eval(!new Gen<string>().EqualNull(_string));
Eval(new Gen<string>().EqualNull(null));

var _object = new object();
if (new Gen<object>().EqualNull(_object)) return 4;
if (!new Gen<object>().EqualNull(null)) return 5;
Eval(!new Gen<object>().EqualNull(_object));
Eval(new Gen<object>().EqualNull(null));

return 0;
return _result;
}
}
}
27 changes: 21 additions & 6 deletions Tests/Generics/GenericFields/StaticAssignmentClass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GenericFields
using System;

namespace GenericFields
{
internal class StaticAssignmentClass
{
Expand All @@ -13,18 +15,31 @@ public T Assign(T t)
}
}

public static int RunTests()
private static int _counter = 0;
private static bool _result = true;
public static void Eval(bool exp)
{
_counter++;
if (!exp)
{
_result = exp;
Console.Write("StaticAssignmentClass failed at location: ");
Console.WriteLine(_counter);
}
}

public static bool RunTests()
{
int _int = 1;
if (new Gen<int>().Assign(_int) != _int) return 1;
Eval(new Gen<int>().Assign(_int) == _int);

string _string = "string";
if (new Gen<string>().Assign(_string) != _string) return 2;
Eval(new Gen<string>().Assign(_string) == _string);

var _object = new object();
if (new Gen<object>().Assign(_object) != _object) return 3;
Eval(new Gen<object>().Assign(_object) == _object);

return 0;
return _result;
}
}
}
27 changes: 21 additions & 6 deletions Tests/Generics/GenericFields/StaticAssignmentStruct.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GenericFields
using System;

namespace GenericFields
{
internal class StaticAssignmentStruct
{
Expand All @@ -13,18 +15,31 @@ public T Assign(T t)
}
}

public static int RunTests()
private static int _counter = 0;
private static bool _result = true;
public static void Eval(bool exp)
{
_counter++;
if (!exp)
{
_result = exp;
Console.Write("StaticAssignmentStruct failed at location: ");
Console.WriteLine(_counter);
}
}

public static bool RunTests()
{
int _int = 1;
if (new Gen<int>().Assign(_int) != _int) return 1;
Eval(new Gen<int>().Assign(_int) == _int);

string _string = "string";
if (new Gen<string>().Assign(_string) != _string) return 2;
Eval(new Gen<string>().Assign(_string) == _string);

var _object = new object();
if (new Gen<object>().Assign(_object) != _object) return 3;
Eval(new Gen<object>().Assign(_object) == _object);

return 0;
return _result;
}
}
}
33 changes: 24 additions & 9 deletions Tests/Generics/GenericFields/StaticEqualNullClass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GenericFields
using System;

namespace GenericFields
{
internal class StaticEqualNullClass
{
Expand All @@ -9,24 +11,37 @@ public class Gen<T>
public bool EqualNull(T? t)
{
Field1 = t;
return ((object)Field1! == null);
return ((object?)Field1 == null);
}
}

private static int _counter = 0;
private static bool _result = true;
public static void Eval(bool exp)
{
_counter++;
if (!exp)
{
_result = exp;
Console.Write("StaticEqualNullClass failed at location: ");
Console.WriteLine(_counter);
}
}

public static int RunTests()
public static bool RunTests()
{
int _int = 1;
if (new Gen<int>().EqualNull(_int)) return 1;
Eval(!new Gen<int>().EqualNull(_int));

string _string = "string";
if (new Gen<string>().EqualNull(_string)) return 2;
if (!new Gen<string>().EqualNull(null)) return 3;
Eval(!new Gen<string>().EqualNull(_string));
Eval(new Gen<string>().EqualNull(null));

var _object = new object();
if (new Gen<object>().EqualNull(_object)) return 4;
if (!new Gen<object>().EqualNull(null)) return 5;
Eval(!new Gen<object>().EqualNull(_object));
Eval(new Gen<object>().EqualNull(null));

return 0;
return _result;
}
}
}
Loading

0 comments on commit b356312

Please sign in to comment.