(t *testing.T, plans []testUTPs)
| 35 | } |
| 36 | |
| 37 | func testRunTest(t *testing.T, plans []testUTPs) { |
| 38 | t.Helper() |
| 39 | count.Tests(t, len(plans)*2) |
| 40 | |
| 41 | lang.InitEnv() |
| 42 | lang.ShellProcess.Config.Set("test", "auto-report", false, nil) |
| 43 | |
| 44 | var pubPriv string |
| 45 | |
| 46 | for i := range plans { |
| 47 | for j := 1; j < 3; j++ { // test public functions the private functions |
| 48 | |
| 49 | fileRef := &ref.File{ |
| 50 | Source: &ref.Source{ |
| 51 | Filename: "foobar.mx", |
| 52 | Module: fmt.Sprintf("foobar/mod-%d-%d-%d", atomic.AddInt32(&uniq, 1), i, j), |
| 53 | DateTime: time.Now(), |
| 54 | }, |
| 55 | } |
| 56 | |
| 57 | if j == 1 { |
| 58 | lang.MxFunctions.Define(plans[i].Function, nil, []rune(plans[i].TestBlock), fileRef) |
| 59 | pubPriv = "public" |
| 60 | } else { |
| 61 | lang.PrivateFunctions.Define(plans[i].Function, nil, []rune(plans[i].TestBlock), fileRef) |
| 62 | plans[i].Function = fileRef.Source.Module + "/" + plans[i].Function |
| 63 | pubPriv = "private" |
| 64 | } |
| 65 | |
| 66 | ut := new(lang.UnitTests) |
| 67 | ut.Add(plans[i].Function, &plans[i].UTP, fileRef) |
| 68 | |
| 69 | if ut.Run(lang.ShellProcess, plans[i].Function) != plans[i].Passed { |
| 70 | if plans[i].Passed { |
| 71 | t.Errorf("Unit test %s %d failed", pubPriv, i) |
| 72 | b, err := json.MarshalIndent(lang.ShellProcess.Tests.Results.Dump(), "", " ") |
| 73 | if err != nil { |
| 74 | panic(err) |
| 75 | } |
| 76 | |
| 77 | t.Logf(" Test report:\n%s", b) |
| 78 | |
| 79 | } else { |
| 80 | t.Errorf("Unit test %s %d passed when expected to fail", pubPriv, i) |
| 81 | } |
| 82 | } |
| 83 | lang.ShellProcess.Tests.Results = new(lang.TestResults) |
| 84 | } |
| 85 | } |
| 86 | } |
no test coverage detected