kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/util/tools/print_test_status/print_test_status.go (about) 1 /* 2 * Copyright 2015 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Binary print_test_status takes a single argument that is a path to file with 18 // an protobuf wire-encoding of a Bazel TestResultData and prints it as JSON to 19 // stdout. 20 package main 21 22 import ( 23 "context" 24 "encoding/json" 25 "flag" 26 "io/ioutil" 27 "os" 28 29 "kythe.io/kythe/go/platform/vfs" 30 "kythe.io/kythe/go/util/log" 31 32 "google.golang.org/protobuf/proto" 33 34 tspb "kythe.io/third_party/bazel/test_status_go_proto" 35 ) 36 37 func main() { 38 flag.Parse() 39 40 f, err := vfs.Open(context.Background(), flag.Arg(0)) 41 if err != nil { 42 log.Fatal(err) 43 } 44 45 data, err := ioutil.ReadAll(f) 46 f.Close() 47 if err != nil { 48 log.Fatal(err) 49 } 50 51 var tr tspb.TestResultData 52 if err := proto.Unmarshal(data, &tr); err != nil { 53 log.Fatal(err) 54 } 55 56 if err := json.NewEncoder(os.Stdout).Encode(&tr); err != nil { 57 log.Fatal(err) 58 } 59 60 }