github.com/neilgarb/delve@v1.9.2-nobreaks/cmd/dlv/cmds/cmds_test.go (about)

     1  package cmds
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestParseRedirects(t *testing.T) {
     8  	testCases := []struct {
     9  		in     []string
    10  		tgt    [3]string
    11  		tgterr string
    12  	}{
    13  		{
    14  			[]string{"one.txt"},
    15  			[3]string{"one.txt", "", ""},
    16  			"",
    17  		},
    18  		{
    19  			[]string{"one.txt", "two.txt"},
    20  			[3]string{},
    21  			"redirect error: stdin redirected twice",
    22  		},
    23  		{
    24  			[]string{"stdout:one.txt"},
    25  			[3]string{"", "one.txt", ""},
    26  			"",
    27  		},
    28  		{
    29  			[]string{"stdout:one.txt", "stderr:two.txt", "stdin:three.txt"},
    30  			[3]string{"three.txt", "one.txt", "two.txt"},
    31  			"",
    32  		},
    33  		{
    34  			[]string{"stdout:one.txt", "stderr:two.txt", "three.txt"},
    35  			[3]string{"three.txt", "one.txt", "two.txt"},
    36  			"",
    37  		},
    38  	}
    39  
    40  	for _, tc := range testCases {
    41  		t.Logf("input: %q", tc.in)
    42  		out, err := parseRedirects(tc.in)
    43  		t.Logf("output: %q error %v", out, err)
    44  		if tc.tgterr != "" {
    45  			if err == nil {
    46  				t.Errorf("Expected error %q, got output %q", tc.tgterr, out)
    47  			} else if errstr := err.Error(); errstr != tc.tgterr {
    48  				t.Errorf("Expected error %q, got error %q", tc.tgterr, errstr)
    49  			}
    50  		} else {
    51  			for i := range tc.tgt {
    52  				if tc.tgt[i] != out[i] {
    53  					t.Errorf("Expected %q, got %q (mismatch at index %d)", tc.tgt, out, i)
    54  					break
    55  				}
    56  			}
    57  		}
    58  	}
    59  }