Line data Source code
1 : // Copyright 2024 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : package testutils 6 : 7 : // CheckErr can be used to simplify test code that expects no errors. 8 : // Instead of: 9 : // 10 : // v, err := SomeFunc() 11 : // if err != nil { .. } 12 : // 13 : // we can use: 14 : // 15 : // v := testutils.CheckErr(someFunc()) 16 1 : func CheckErr[V any](v V, err error) V { 17 1 : if err != nil { 18 0 : panic(err) 19 : } 20 1 : return v 21 : } 22 : 23 : // CheckErr2 can be used to simplify test code that expects no errors. 24 : // Instead of: 25 : // 26 : // v, w, err := SomeFunc() 27 : // if err != nil { .. } 28 : // 29 : // we can use: 30 : // 31 : // v, w := testutils.CheckErr2(someFunc()) 32 0 : func CheckErr2[V any, W any](v V, w W, err error) (V, W) { 33 0 : if err != nil { 34 0 : panic(err) 35 : } 36 0 : return v, w 37 : }