diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-08-05 10:03:38 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-08-07 10:01:30 +0000 |
| commit | 04cffc22d57a9014cb89df6c9f44de50d2eb2b9b (patch) | |
| tree | b6b5ff4cd8afb9342a2fc5d8dfaff21a4766139b /vm/vm_test.go | |
| parent | a9fce3b50a00a8dab6365de4c22749f4bd1f1ac6 (diff) | |
vm: refactoring
1. func Run optionally accepts the opts.
2. Some refactoring, more comments.
Diffstat (limited to 'vm/vm_test.go')
| -rw-r--r-- | vm/vm_test.go | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/vm/vm_test.go b/vm/vm_test.go index f550cc89a..5034b1fa3 100644 --- a/vm/vm_test.go +++ b/vm/vm_test.go @@ -76,10 +76,7 @@ func (inst *testInstance) Close() error { } func init() { - beforeContextDefault = maxErrorLength + 100 - tickerPeriod = 1 * time.Second vmimpl.WaitForOutputTimeout = 3 * time.Second - ctor := func(env *vmimpl.Env) (vmimpl.Pool, error) { return &testPool{}, nil } @@ -89,6 +86,13 @@ func init() { }) } +func withTestRunOptionsDefaults() func(*RunOptions) { + return func(opts *RunOptions) { + opts.beforeContext = maxErrorLength + 100 + opts.tickerPeriod = 1 * time.Second + } +} + type Test struct { Name string Exit ExitCondition @@ -278,7 +282,7 @@ var tests = []*Test{ Body: func(outc chan []byte, errc chan error) { for i := 0; i < 5; i++ { time.Sleep(time.Second) - outc <- append(executingProgram, '\n') + outc <- []byte(executedProgramsStart + "\n") } errc <- nil }, @@ -307,7 +311,7 @@ var tests = []*Test{ Name: "split-line", Exit: ExitNormal, Body: func(outc chan []byte, errc chan error) { - // "ODEBUG:" lines should be ignored, however the matchPos logic + // "ODEBUG:" lines should be ignored, however the curPos logic // used to trim the lines so that we could see just "BUG:" later // and detect it as crash. buf := new(bytes.Buffer) @@ -381,12 +385,11 @@ func testMonitorExecution(t *testing.T, test *Test) { testInst.diagnoseNoWait = test.DiagnoseNoWait done := make(chan bool) finishCalled := 0 - finishCb := EarlyFinishCb(func() { finishCalled++ }) - opts := []any{test.Exit, finishCb} var inject chan bool + injectExecuting := func(opts *RunOptions) {} if test.BodyExecuting != nil { inject = make(chan bool, 10) - opts = append(opts, InjectExecuting(inject)) + injectExecuting = WithInjectExecuting(inject) } else { test.BodyExecuting = func(outc chan []byte, errc chan error, inject chan<- bool) { test.Body(outc, errc) @@ -396,7 +399,12 @@ func testMonitorExecution(t *testing.T, test *Test) { test.BodyExecuting(testInst.outc, testInst.errc, inject) done <- true }() - _, rep, err := inst.Run(context.Background(), reporter, "", opts...) + _, rep, err := inst.Run(context.Background(), reporter, "", + withTestRunOptionsDefaults(), + WithExitCondition(test.Exit), + WithEarlyFinishCb(func() { finishCalled++ }), + injectExecuting, + ) if err != nil { t.Fatal(err) } |
