1// Copyright 2017 Google LLC. All Rights Reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package gnostic_extension_v1 16 17import ( 18 "os" 19 "os/exec" 20 "testing" 21) 22 23func TestExtensionHandlerWithLibraryExample(t *testing.T) { 24 outputFile := "library-example-with-ext.text.out" 25 inputFile := "../testdata/library-example-with-ext.json" 26 referenceFile := "../testdata/library-example-with-ext.text.out" 27 28 os.Remove(outputFile) 29 // run the compiler 30 var err error 31 32 command := exec.Command( 33 "gnostic", 34 "--x-sampleone", 35 "--x-sampletwo", 36 "--text-out="+outputFile, 37 "--resolve-refs", 38 inputFile) 39 40 _, err = command.Output() 41 if err != nil { 42 t.Logf("Compile failed for command %v: %+v", command, err) 43 t.FailNow() 44 } 45 //_ = ioutil.WriteFile(outputFile, output, 0644) 46 err = exec.Command("diff", outputFile, referenceFile).Run() 47 if err != nil { 48 t.Logf("Diff failed: %+v", err) 49 t.FailNow() 50 } else { 51 // if the test succeeded, clean up 52 os.Remove(outputFile) 53 } 54} 55