1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-21 09:27:59 +02:00

Test improvements (continue after fail, console output, error location)

This commit is contained in:
Brian Fiete 2020-12-29 09:23:00 -08:00
parent cadd1f809f
commit 78ae79b802
7 changed files with 356 additions and 68 deletions

View file

@ -1,23 +1,78 @@
using System.IO;
namespace System
{
class Test
{
[NoReturn]
public static void FatalError(String msg = "Test fatal error encountered")
public class TestStream : Stream
{
Internal.FatalError(msg, 1);
public override int64 Position
{
get
{
Runtime.FatalError();
}
set
{
}
}
public override int64 Length
{
get
{
Runtime.FatalError();
}
}
public override bool CanRead
{
get
{
return false;
}
}
public override bool CanWrite
{
get
{
return true;
}
}
public override Result<int> TryRead(Span<uint8> data)
{
return default;
}
public override Result<int> TryWrite(Span<uint8> data)
{
String str = scope String();
str.Append((char8*)data.Ptr, data.Length);
Internal.[Friend]Test_Write(str.CStr());
return .Ok(data.Length);
}
public override void Close()
{
}
}
public static void Assert(bool condition)
public static void FatalError(String msg = "Test fatal error encountered", String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
if (!condition)
Internal.FatalError("Test Assert failed", 1);
String failStr = scope .()..AppendF("{} at line {} in {}", msg, line, filePath);
Internal.[Friend]Test_Error(failStr);
}
public static void Assert(bool condition, String error)
public static void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
if (!condition)
Internal.FatalError(error, 2);
{
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
Internal.[Friend]Test_Error(failStr);
}
}
}
}