59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
|
|
using bts.api;
|
|
using bts.api.core;
|
|
using bts.api.test;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System.Diagnostics;
|
|
|
|
namespace bts.test {
|
|
public static class InProcessTestRunner {
|
|
|
|
public static void run_test_synchronously(string v, TestType type, TestEnumerator enumerator, Action<TestResult> report) {
|
|
foreach (var t in enumerator.find(v,type)) {
|
|
run_test_synchronously(t, report);
|
|
}
|
|
}
|
|
public static void run_test_synchronously(TestMethod test, Action<TestResult> report) {
|
|
var result = new TestResult() {
|
|
TestName = test.full_name,
|
|
Status = TestResult.Types.Step.Setup,
|
|
};
|
|
try {
|
|
if (test.ignored) {
|
|
result.Status = TestResult.Types.Step.Ignored;
|
|
result.Message = test.ignored_reason;
|
|
return;
|
|
}
|
|
|
|
var live = test.setup();
|
|
result.Status = TestResult.Types.Step.Test;
|
|
object test_result = live.run();
|
|
if (test_result is Task t) {
|
|
t.Wait();
|
|
}
|
|
result.Status = TestResult.Types.Step.Teardown;
|
|
live.Dispose();
|
|
result.Status = TestResult.Types.Step.Pass;
|
|
}
|
|
catch (AssertFailure af) {
|
|
result.Message = $"Assertion Failure:\n{af.Message}\nLocation:{af._filename}:{af._line}";
|
|
}
|
|
catch (Exception ue) {
|
|
if (ue.InnerException is AssertFailure af) {
|
|
result.Message = $"Assertion Failure:\n{af.Message}\nLocation:{af._filename}:{af._line}";
|
|
}
|
|
else if (ue.InnerException != null) {
|
|
result.Message = $"Unexpected error: {ue.InnerException}";
|
|
}
|
|
else {
|
|
result.Message = $"Unexpected error: {ue.Message}\n\n{ue.StackTrace}";
|
|
}
|
|
}
|
|
finally {
|
|
report(result);
|
|
}
|
|
}
|
|
}
|
|
} |