github.com/ratrocket/u-root@v0.0.0-20180201221235-1cf9f48ee2cf/cmds/hexdump/hexdump_test.go (about) 1 // Copyright 2017 the u-root 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 "os/exec" 11 "testing" 12 13 "github.com/u-root/u-root/pkg/testutil" 14 ) 15 16 var tests = []struct { 17 in []byte 18 out []byte 19 }{ 20 { 21 in: []byte("abcdefghijklmnopqrstuvwxyz"), 22 out: []byte( 23 `00000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 |abcdefghijklmnop| 24 00000010 71 72 73 74 75 76 77 78 79 7a |qrstuvwxyz| 25 `), 26 }, 27 } 28 29 func TestHexdump(t *testing.T) { 30 tmpDir, execPath := testutil.CompileInTempDir(t) 31 defer os.RemoveAll(tmpDir) 32 33 for _, tt := range tests { 34 cmd := exec.Command(execPath) 35 cmd.Stdin = bytes.NewReader(tt.in) 36 out, err := cmd.CombinedOutput() 37 if err != nil { 38 t.Fatal(err) 39 } 40 41 if !bytes.Equal(out, tt.out) { 42 t.Errorf("want=%#v; got=%#v", tt.out, tt) 43 } 44 } 45 }