package tests import ( "fmt" "os" "testing" "time" "git.bizdoc.ro/gabi-public/Advent-of-Code.git/aoc" ) func assert(t *testing.T, err error, a, b any) { if err != nil { t.Error(err) } want := fmt.Sprintf("%v", a) got := fmt.Sprintf("%v", b) if got != want { err = fmt.Errorf("want %s, got %s", want, got) t.Error(err) } } func Handler[T any](f func(ctx aoc.Context) (T, error)) func(ctx aoc.Context) (any, error) { return func(c aoc.Context) (any, error) { return f(c) } } func Handler2[T any, K any](param T, f func(ctx aoc.Context, param T) (K, error)) func(ctx aoc.Context) (any, error) { return func(c aoc.Context) (any, error) { return f(c, param) } } func Test(t *testing.T, file string, handler func(aoc.Context) (any, error), want any) { f, err := os.Open("tmp/" + file) if err != nil { panic(err) } defer f.Close() start := time.Now() got, err := handler(aoc.Context{ Body: f, Logger: nil, Context: nil, }) t.Log("took", time.Since(start)) assert(t, err, want, got) }