go-hep.org/x/hep@v0.38.1/groot/cmd/root-dump/main_test.go (about)

     1  // Copyright ©2018 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"bytes"
     9  	"os"
    10  	"testing"
    11  
    12  	"go-hep.org/x/hep/internal/diff"
    13  )
    14  
    15  func TestROOTDump(t *testing.T) {
    16  	const deep = true
    17  	for _, tc := range []struct {
    18  		name string
    19  		want string
    20  	}{
    21  		{
    22  			name: "../../testdata/simple.root",
    23  			want: "testdata/simple.txt",
    24  		},
    25  	} {
    26  		t.Run(tc.name, func(t *testing.T) {
    27  			o := new(bytes.Buffer)
    28  			err := dump(o, tc.name, deep)
    29  			if err != nil {
    30  				t.Fatalf("could not dump %q: %+v", tc.name, err)
    31  			}
    32  
    33  			want, err := os.ReadFile(tc.want)
    34  			if err != nil {
    35  				t.Fatalf("could not read reference file: %+v", err)
    36  			}
    37  
    38  			if got, want := o.String(), string(want); got != want {
    39  				t.Fatalf("error:\n%s\n", diff.Format(got, want))
    40  			}
    41  		})
    42  	}
    43  }