81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
|
|
using bts.test;
|
|
using ManyConsole;
|
|
using System;
|
|
using mbts;
|
|
using System.Collections.Generic;
|
|
using bts.api.test;
|
|
using System.Threading.Tasks;
|
|
using mbts.config;
|
|
using System.Linq;
|
|
|
|
namespace sparkcmd {
|
|
public class TestCommand : ConsoleCommand {
|
|
uint _timeout = 0;
|
|
uint _parallel = 1;
|
|
bool _list;
|
|
|
|
public TestCommand() {
|
|
IsCommand("test", "Run managed unit tests");
|
|
// i comes thorugh as "t" which seems daft.
|
|
HasOption("t|timeout", "Timeout unit tests", i => _timeout = 10);
|
|
HasOption<uint>("n|parallel", "How many tests to run in parallel", i => _parallel = i);
|
|
HasOption("l|list", "List all tests", _ => _list = true);
|
|
HasAdditionalArguments(null, " [Test List]");
|
|
}
|
|
|
|
public override int Run(string[] tests) {
|
|
if (_list) {
|
|
list_tests();
|
|
return 0;
|
|
}
|
|
|
|
//Configuration.initialize_for_test();
|
|
|
|
if (_timeout == 0 && tests.Length == 1) {
|
|
//System.Threading.Thread.Sleep(5000);
|
|
using (var trr = new TestResultReceiver(true)) {
|
|
InProcessTestRunner.run_test_syncronously(tests[0], Enumerator, trr.get_reporter());
|
|
trr.print_summary();
|
|
return trr.ErrorCount;
|
|
}
|
|
}
|
|
else if (tests.Length > 0) {
|
|
return run_tests(Enumerator.match(tests).Select(t => t.name));
|
|
}
|
|
else {
|
|
return run_tests(Enumerator.Tests.Select(t => t.full_name));
|
|
}
|
|
}
|
|
|
|
Lazy<TestEnumerator> _enumerator = new Lazy<TestEnumerator>(() => new TestEnumerator("spark_test"));
|
|
TestEnumerator Enumerator => _enumerator.Value;
|
|
|
|
int run_tests(IEnumerable<string> tests) {
|
|
var runner = new TestRunner();
|
|
// waits for all child processes to exit or time out
|
|
return runner.run_tests(tests, Math.Max(_timeout,10));
|
|
}
|
|
|
|
void list_tests() {
|
|
Console.WriteLine("All tests: ");
|
|
foreach (var t in Enumerator.TestGroups) {
|
|
ConsoleEx.WriteLine(t.name, ConsoleColor.Green);
|
|
foreach (var test in t.methods) {
|
|
Console.Write($" {test.name}");
|
|
if (test.ignored) {
|
|
var reason = test.ignored_reason;
|
|
if (string.IsNullOrEmpty(reason)) {
|
|
ConsoleEx.Write(" (ignored)", ConsoleColor.Yellow);
|
|
}
|
|
else {
|
|
ConsoleEx.Write($" (ignored: '{test.ignored_reason}')", ConsoleColor.Yellow);
|
|
}
|
|
}
|
|
Console.WriteLine();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|