Run all unit tests against a specific murex function
(p *Process, function string)
| 64 | |
| 65 | // Run all unit tests against a specific murex function |
| 66 | func (ut *UnitTests) Run(p *Process, function string) bool { |
| 67 | ut.mutex.Lock() |
| 68 | utCopy := make([]*unitTest, len(ut.units)) |
| 69 | copy(utCopy, ut.units) |
| 70 | ut.mutex.Unlock() |
| 71 | |
| 72 | var ( |
| 73 | passed = true |
| 74 | exists bool |
| 75 | ) |
| 76 | |
| 77 | autoreport, err := p.Config.Get("test", "auto-report", "bool") |
| 78 | if err != nil { |
| 79 | autoreport = true |
| 80 | } |
| 81 | |
| 82 | for i := range utCopy { |
| 83 | if function == "*" || utCopy[i].Function == function { |
| 84 | passed = runTest(p.Tests.Results, utCopy[i].FileRef, utCopy[i].TestPlan, utCopy[i].Function) && passed |
| 85 | exists = true |
| 86 | } |
| 87 | |
| 88 | if autoreport.(bool) { |
| 89 | p.Tests.WriteResults(p.Config, p.Stdout) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if !exists { |
| 94 | passed = false |
| 95 | p.Tests.Results.Add(&TestResult{ |
| 96 | Exec: function, |
| 97 | TestName: testName, |
| 98 | Status: TestError, |
| 99 | Message: fmt.Sprintf("No unit tests exist for: `%s`", function), |
| 100 | }) |
| 101 | |
| 102 | if autoreport.(bool) { |
| 103 | p.Tests.WriteResults(p.Config, p.Stdout) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if passed { |
| 108 | p.ExitNum = 0 |
| 109 | } else { |
| 110 | p.ExitNum = 1 |
| 111 | } |
| 112 | |
| 113 | return passed |
| 114 | } |
| 115 | |
| 116 | // Dump the defined unit tests in a JSONable structure |
| 117 | func (ut *UnitTests) Dump() any { |