1package main 2 3import ( 4 "encoding/json" 5 "fmt" 6 "os" 7 "path/filepath" 8 "strings" 9 "testing" 10) 11 12func Test_stdliblist(t *testing.T) { 13 testDir := t.TempDir() 14 outJSON := filepath.Join(testDir, "out.json") 15 16 test_args := []string{ 17 fmt.Sprintf("-out=%s", outJSON), 18 "-sdk=external/go_sdk", 19 } 20 21 if err := stdliblist(test_args); err != nil { 22 t.Errorf("calling stdliblist got err: %v", err) 23 } 24 f, err := os.Open(outJSON) 25 if err != nil { 26 t.Errorf("cannot open output json: %v", err) 27 } 28 defer func() { _ = f.Close() }() 29 decoder := json.NewDecoder(f) 30 for decoder.More() { 31 var result *flatPackage 32 if err := decoder.Decode(&result); err != nil { 33 t.Errorf("unable to decode output json: %v\n", err) 34 } 35 36 if !strings.HasPrefix(result.ID, "@io_bazel_rules_go//stdlib") { 37 t.Errorf("ID should be prefixed with @io_bazel_rules_go//stdlib :%v", result) 38 } 39 if !strings.HasPrefix(result.ExportFile, "__BAZEL_OUTPUT_BASE__") { 40 t.Errorf("export file should be prefixed with __BAZEL_OUTPUT_BASE__ :%v", result) 41 } 42 for _, gofile := range result.GoFiles { 43 if !strings.HasPrefix(gofile, "__BAZEL_OUTPUT_BASE__/external/go_sdk") { 44 t.Errorf("all go files should be prefixed with __BAZEL_OUTPUT_BASE__/external/go_sdk :%v", result) 45 } 46 } 47 } 48} 49