1 /** 2 Copyright: Copyright (c) 2018, Joakim Brännström. All rights reserved. 3 License: MPL-2 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 6 This Source Code Form is subject to the terms of the Mozilla Public License, 7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain 8 one at http://mozilla.org/MPL/2.0/. 9 10 This file contains the interface used for reporting test cases that are found. 11 */ 12 module dextool.plugin.mutate.backend.test_mutant.interface_; 13 14 import dextool.plugin.mutate.backend.type : TestCase; 15 16 interface TestCaseReport { 17 /// A test case that failed. 18 void reportFailed(TestCase tc) @safe nothrow; 19 20 /// A test case that is found 21 void reportFound(TestCase tc) @safe nothrow; 22 23 /// One or more test cases are unstable. 24 void reportUnstable(TestCase tc) @safe nothrow; 25 } 26 27 /// A simple class to gather reported test cases. 28 class GatherTestCase : TestCaseReport { 29 import std.algorithm : map; 30 import std.array : array; 31 import dextool.set; 32 33 /// Test cases reported as failed. 34 long[TestCase] failed; 35 36 /// The unstable test cases. 37 Set!TestCase unstable; 38 39 /// Found test cases. 40 Set!TestCase found; 41 42 void merge(GatherTestCase o) @safe nothrow { 43 foreach (kv; o.failed.byKeyValue) { 44 if (auto v = kv.key in failed) 45 (*v) += kv.value; 46 else 47 failed[kv.key] = kv.value; 48 } 49 50 foreach (k; setToRange!TestCase(o.found)) { 51 found.add(k); 52 } 53 54 foreach (k; setToRange!TestCase(o.unstable)) { 55 unstable.add(k); 56 } 57 } 58 59 TestCase[] failedAsArray() @safe nothrow { 60 return failed.byKey.array; 61 } 62 63 TestCase[] foundAsArray() @safe nothrow { 64 return setToList!TestCase(found); 65 } 66 67 TestCase[] unstableAsArray() @safe nothrow { 68 return setToList!TestCase(unstable); 69 } 70 71 override void reportFailed(TestCase tc) @safe nothrow { 72 import std.format : format; 73 74 this.reportFound(tc); 75 76 if (auto v = tc in failed) { 77 (*v)++; 78 } else { 79 failed[tc] = 1; 80 } 81 } 82 83 /// A test case that is found 84 override void reportFound(TestCase tc) @safe nothrow { 85 found.add(tc); 86 } 87 88 override void reportUnstable(TestCase tc) @safe nothrow { 89 found.add(tc); 90 unstable.add(tc); 91 } 92 }