...
1 package main
2
3 import (
4 "encoding/json"
5 "fmt"
6 "os"
7 "path/filepath"
8 "strings"
9 "testing"
10 )
11
12 func 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=../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, "@//stdlib:") {
37 t.Errorf("ID should be prefixed with @//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
44 if !strings.HasPrefix(gofile, "go_sdk/") {
45 t.Errorf("all go files should be prefixed with go_sdk/ :%v", result)
46 }
47 }
48 }
49 }
50
View as plain text