go-hep.org/x/hep@v0.38.1/cmd/hepmc2root/main_test.go (about)

     1  // Copyright ©2022 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  	"os"
     9  	"path/filepath"
    10  	"strings"
    11  	"testing"
    12  
    13  	"go-hep.org/x/hep/groot/rcmd"
    14  )
    15  
    16  func TestConvert(t *testing.T) {
    17  	tmp, err := os.MkdirTemp("", "hepmc2root-")
    18  	if err != nil {
    19  		t.Fatalf("could not create tmpdir: %+v", err)
    20  	}
    21  	defer os.RemoveAll(tmp)
    22  
    23  	for _, name := range []string{
    24  		"testdata/small.hepmc",
    25  	} {
    26  		t.Run(name, func(t *testing.T) {
    27  			oname := filepath.Join(tmp, filepath.Base(name)+".root")
    28  			tname := "tree"
    29  
    30  			err := process(oname, tname, name)
    31  			if err != nil {
    32  				t.Fatalf("could not convert %q: %+v", name, err)
    33  			}
    34  
    35  			var (
    36  				out  = new(strings.Builder)
    37  				deep = true
    38  			)
    39  			err = rcmd.Dump(out, oname, deep, nil)
    40  			if err != nil {
    41  				t.Fatalf("could not dump ROOT file %q: %+v", oname, err)
    42  			}
    43  
    44  			want, err := os.ReadFile(name + ".txt")
    45  			if err != nil {
    46  				t.Fatalf("could not load reference file %q: %+v", name, err)
    47  			}
    48  
    49  			if got, want := out.String(), string(want); got != want {
    50  				t.Fatalf("invalid root-dump output:\ngot:\n%s\nwant:\n%s\n", got, want)
    51  			}
    52  		})
    53  	}
    54  }