go-hep.org/x/hep@v0.38.1/groot/cmd/root-ls/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 "path/filepath" 11 "testing" 12 ) 13 14 func TestROOTls(t *testing.T) { 15 tmp, err := os.MkdirTemp("", "root-ls-") 16 if err != nil { 17 t.Fatalf("could not create tmp dir: %+v", err) 18 } 19 defer os.RemoveAll(tmp) 20 21 for _, tc := range []struct { 22 name string 23 rc int 24 }{ 25 { 26 name: "../../testdata/dirs-6.14.00.root", 27 }, 28 { 29 name: "../../testdata/graphs.root", 30 }, 31 { 32 name: "../../testdata/small-flat-tree.root", 33 }, 34 { 35 name: filepath.Join(tmp, "not-there.root"), 36 rc: 1, 37 }, 38 { 39 name: "-h", 40 rc: 0, 41 }, 42 { 43 name: "-=3", 44 rc: 1, 45 }, 46 { 47 name: "-cpu-profile=" + filepath.Join(tmp, "cpu.prof"), 48 rc: 1, 49 }, 50 } { 51 t.Run(tc.name, func(t *testing.T) { 52 out := new(bytes.Buffer) 53 rc := run(out, out, []string{ 54 "-sinfos", "-t", tc.name, 55 }) 56 57 if rc != tc.rc { 58 t.Fatalf( 59 "invalid exit-code for root-ls: got=%d, want=%d\n%s", 60 rc, tc.rc, out.String(), 61 ) 62 } 63 if rc != 0 || tc.name == "-h" { 64 return 65 } 66 67 ref := filepath.Join("testdata", filepath.Base(tc.name)+".txt") 68 want, err := os.ReadFile(ref) 69 if err != nil { 70 t.Fatalf("could not open reference file: %v", err) 71 } 72 if got, want := out.String(), string(want); got != want { 73 t.Fatalf("error:\ngot = %v\nwant= %v\n", got, want) 74 } 75 }) 76 } 77 }