1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-24 02:28:01 +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

@ -376,6 +376,7 @@ namespace System
public bool ShouldFail;
public bool Ignore;
public bool Profile;
public String Tag;
}
public struct ImportAttribute : Attribute

View file

@ -68,14 +68,18 @@ namespace System
{
if (outStreamWriter == null)
{
Stream stream;
#if BF_TEST_BUILD
stream = new Test.TestStream();
#else
FileStream fileStream = new .();
Stream stream = fileStream;
stream = fileStream;
if (fileStream.OpenStd(stdKind) case .Err)
{
DeleteAndNullify!(fileStream);
stream = new NullStream();
}
#endif
StreamWriter newStreamWriter = new StreamWriter(stream, InputEncoding, 4096, true);
newStreamWriter.AutoFlush = true;

View file

@ -108,6 +108,10 @@ namespace System
[CallingConvention(.Cdecl)]
static extern void Test_Init(char8* testData);
[CallingConvention(.Cdecl)]
static extern void Test_Error(char8* error);
[CallingConvention(.Cdecl)]
static extern void Test_Write(char8* str);
[CallingConvention(.Cdecl)]
static extern int32 Test_Query();
[CallingConvention(.Cdecl)]
static extern void Test_Finish();

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);
}
}
}
}