Source file src/cmd/cgo/internal/test/issue9026/issue9026.go
1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package issue9026 6 7 // This file appears in its own package since the assertion tests the 8 // per-package counter used to create fresh identifiers. 9 10 /* 11 typedef struct { int i; } git_merge_file_input; 12 13 typedef struct { int j; } git_merge_file_options; 14 15 void git_merge_file( 16 git_merge_file_input *in, 17 git_merge_file_options *opts) {} 18 */ 19 import "C" 20 import ( 21 "fmt" 22 "testing" 23 ) 24 25 func Test(t *testing.T) { 26 var in C.git_merge_file_input 27 var opts *C.git_merge_file_options 28 C.git_merge_file(&in, opts) 29 30 // Test that the generated type names are deterministic. 31 // (Previously this would fail about 10% of the time.) 32 // 33 // Brittle: the assertion may fail spuriously when the algorithm 34 // changes, but should remain stable otherwise. 35 got := fmt.Sprintf("%T %T", in, opts) 36 want := "issue9026._Ctype_struct___0 *issue9026._Ctype_struct___1" 37 if got != want { 38 t.Errorf("Non-deterministic type names: got %s, want %s", got, want) 39 } 40 } 41