code
stringlengths
10
1.34M
language
stringclasses
1 value
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that illegal function signatures are detected. // Does not compile. package main type t1 int type t2 int type t3 int func f1(*t2, x ...
Go
// build // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test basic concurrency: the classic prime sieve. // Do not run - loops forever. package main // Send the sequence 2, 3, 4, ... to channel 'ch'. f...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test character literal syntax. package main import "os" func main() { var i uint64 = ' ' + 'a' + 'ä' + '本' + '\a' + '\b' + '\f' + ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test types of constant expressions, using reflect. package main import "reflect" func typeof(x interface{}) string { return reflect.TypeOf(x).Stri...
Go
// $G $D/$F.go $D/z*.go && $L $F.$A && ./$A.out // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main func main() { F1() F2() F3() F4() F5() F6() F7() F8() F9() F10() F11() F12() F13() F14() F15() F16...
Go
//line x6.go:4 package main func F6() {}
Go
//line x17.go:4 package main func F17() {}
Go
//line x10.go:4 package main func F10() {}
Go
//line x2.go:4 package main func F2() {}
Go
//line x12.go:4 package main func F12() {}
Go
//line x4.go:4 package main func F4() {}
Go
//line x9.go:4 package main func F9() {}
Go
//line x11.go:4 package main func F11() {}
Go
//line x14.go:4 package main func F14() {}
Go
//line x16.go:4 package main func F16() {}
Go
//line x13.go:4 package main func F13() {}
Go
//line x18.go:4 package main func F18() {}
Go
//line x7.go:4 package main func F7() {}
Go
//line x19.go:4 package main func F19() {}
Go
//line x5.go:4 package main func F5() {}
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //line foo/bar.y:4 package main //line foo/bar.y:60 func main() { //line foo/bar.y:297 f, l := 0, 0 //line yacctab:1 f, l = 1, 1 //line yaccpar:1 f,...
Go
//line x15.go:4 package main func F15() {}
Go
//line x8.go:4 package main func F8() {}
Go
//line x1.go:4 package main func F1() {}
Go
//line x3.go:4 package main func F3() {}
Go
//line x20.go:4 package main func F20() {}
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test reordering of assignments. package main import "fmt" func main() { p1() p2() p3() p4() p5() p6() p7() p8() p9() } var gx []int fu...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main // Test for correct heap-moving of escaped variables. // It is hard to check for the allocations, but it is easy // to check that if you c...
Go
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go || echo BUG:bug434 // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package ignored
Go
// $G $D/$F.go && $L $F.$A && ./$A.out // # switch above to 'run' when bug gets fixed. // # right now it only breaks on 8g // Test for 8g register move bug. The optimizer gets confused // about 16- vs 32-bit moves during splitContractIndex. package main func main() { const c = 0x12345678 index, n, offset := split...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package one // Issue 3552 type T struct { int } func (t T) F() int { return t.int } type U struct { int int } func (u U) F() int { return u.int } type li...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Use the functions in one.go so that the inlined // forms get type-checked. package two import "./one" func use() { var t one.T var u one.U var v one.V...
Go
// echo bug395 is broken # takes 90+ seconds to break // # $G $D/$F.go || echo bug395 // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Issue 1909 // Would OOM due to exponential recursion on Foo's expand...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple methods of various types, with pointer and // value receivers. package main type S string type S1 string type I int type I1 int type T ...
Go
// errorcheck // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that a couple of illegal variable declarations are caught by the compiler. // Does not compile. package main func main() { _ = asdf...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test UTF-8 in strings and character constants. package main import "unicode/utf8" func main() { var chars [6]rune chars[0] = 'a' chars[1] = 'b'...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that method redeclarations are caught by the compiler. // Does not compile. package main type T struct { } func (t *T) M(int, string)...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test for loops. package main func assertequal(is, shouldbe int, msg string) { if is != shouldbe { print("assertion fail", msg, "\n") panic(1) ...
Go
// $G $D/$F.go && $L $F.$A && // ./$A.out -pass 0 >tmp.go && $G tmp.go && $L -o $A.out1 tmp.$A && ./$A.out1 && // ./$A.out -pass 1 >tmp.go && errchk $G -e tmp.go && // ./$A.out -pass 2 >tmp.go && errchk $G -e tmp.go // rm -f tmp.go $A.out1 // Copyright 2010 The Go Authors. All rights reserved. // Use of this source c...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test functions and goroutines. package main func caller(f func(int, int) int, a, b int, c chan int) { c <- f(a, b) } func gocall(f func(int, int)...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test iota. package main func assert(cond bool, msg string) { if !cond { print("assertion fail: ", msg, "\n") panic(1) } } const ( x int = i...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simulating a Turing machine, sort of. package main // brainfuck var p, pc int var a [30000]byte const prog = "++++++++++[>+++++++>++++++++++...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that illegal uses of composite literals are detected. // Does not compile. package main var a = []int { "a" }; // ERROR "conver|incom...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test behavior of the blank identifier (_). package main import _ "fmt" var call string type T struct { _, _, _ int } func (T) _() { } func (T)...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test the cap predeclared function applied to channels. package main func main() { c := make(chan int, 10) if len(c) != 0 || cap(c) != 10 { prin...
Go
// $G -S $D/$F.go | egrep initdone >/dev/null && echo BUG sinit || true // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that many initializations can be done at link time and // generate no executab...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that renamed identifiers no longer have their old meaning. // Does not compile. package main func main() { var n byte // ERRO...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test for loops of many forms. package main func assertequal(is, shouldbe int, msg string) { if is != shouldbe { print("assertion fail" + msg + "...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test scoping of variables. package main var x,y int; func main() { x = 15; y = 20; { var x int; x = 25; y = 25; _ = x; } x = x+y; ...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test composition, decomposition, and reflection on complex numbers. package main import "unsafe" import "reflect" const ( R = 5 I = 6i C1 = R ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test basic operations of slices and arrays. package main var bx [10]byte var by []byte var fx [10]float64 var fy []float64 var lb, hb int var t int...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple arithmetic and assignment for complex numbers. package main const ( R = 5 I = 6i C1 = R + I // ADD(5,6) ) func main() { var b boo...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple functions. package main func main() { var x int; x = fun(10,20,30); if x != 60 { panic(x); } } func fun(ia,ib,ic int)int { var o ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple multi-argument multi-valued function. package main func main() { var x,y int; x,y = simple(10,20,30); if x+y != 65 { panic(x+y); } ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test interface assignment. package main type Iputs interface { puts (s string) string; } // --------- type Print struct { whoami int; put Iput...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test method invocation with pointer receivers and function-valued fields. package main type C struct { a int; x func(p *C)int; } func (this *C) ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test communication operations including select. package main import "os" import "runtime" import "sync" var randx int func nrand(n int) int { ra...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test complex numbers,including fmt support. // Used to crash. package main import "fmt" const ( R = 5 I = 6i C1 = R + I // ADD(5,6) ) func wa...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test integer modulus by contstants. package main import "math/rand" const Count = 1e5 func i64rand() int64 { for { a := int64(rand.Uint32()) ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test basic operations on bool. package main type s struct { a bool; b bool; } func main() { var a,b bool; a = true; b = false; if !a { pan...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test pointers and the . (selector) operator on structs. package main type x2 struct { a,b,c int; d int; }; var g1 x2; var g2 struct { a,b,c int; d ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test integer division and modulus. package main const ( // example from the spec n1 = +5 n2 = -5 d1 = +3 d2 = -3 q1 = +1 q2 = -1 q3 = -1 ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple arithmetic conversion. package main type vlong int64 type short int16 func main() { s1 := vlong(0) for i := short(0); i < 10; i = i ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test interfaces and methods. package main type S struct { a,b int; } type I1 interface { f ()int; } type I2 interface { g() int; f() int; } ...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test compound types made of complex numbers. package main var a [12]complex128 var s []complex128 var c chan complex128 var f struct { c complex12...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test slicing and re-slicing. package main var bx []byte var by []byte var fx []float64 var fy []float64 var lb, hb int var t int func main() { /...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple function literals. package main func main() { x := func(a int)int { x := func(a int)int { x := func(a int)int { return a+5; ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test general operation using s-list. // First Go program ever run (although not in this exact form). package main import "fmt" const nilchar = 0 ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test communication with multiple simultaneous goroutines. package main import "runtime" const N = 1000 // sent messages const M = 10 // receivin...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test general operation using a list implementation. package main type Item interface { Print() string } type ListItem struct { item Item next *...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test, near-exhaustive, of converting numbers between types. // No complex numbers though. package main var i8 int8; var u8 uint8; var i16 int16; va...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test interfaces on basic types. package main type myint int type mystring string type I0 interface{} func f() { var ia, ib I0 var i myint var s...
Go
// cmpout // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test trivial, bootstrap-level complex numbers, including printing. package main const ( R = 5 I = 6i C1 = R + I // ADD(5,6) ) func doprint(...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test integer division by constants. package main import "math/rand" const Count = 1e5 func i64rand() int64 { for { a := int64(rand.Uint32()) ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test arrays and slices. package main func setpd(a []int) { // print("setpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); for i := 0; i < len(a...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple for loop. package main func main() { var t,i int; for i=0; i<100; i=i+1 { t = t+i; } if t != 50*99 { panic(t); } }
Go
// cmpout // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test string operations including printing. package main func main() { var c string a := `abc` b := `xyz` /* print a literal */ print(`abc...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test arithmetic on complex numbers, including multiplication and division. package main const ( R = 5 I = 6i C1 = R + I // ADD(5,6) C2 = R ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple operations on arrays. package main var b[10] float32; func main() { var a[10] float32; for i:=int16(5); i<10; i=i+1 { a[i] = floa...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test simple switch. package main func main() { r := "" a := 3 for i := 0; i < 10; i = i + 1 { switch i { case 5: r += "five" case a, 7:...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test functions of many signatures. package main func assertequal(is, shouldbe int, msg string) { if is != shouldbe { print("assertion fail" + ms...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test struct-valued variables (not pointers). package main type x2 struct { a,b,c int; d int; }; var g1 x2; var g2 struct { a,b,c int; d x2; }; fun...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test goto and labels. package main func main() { i := 0 if false { goto gogoloop } if false { goto gogoloop } if false { goto gogoloop ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test composite literals. package main type M map[int]int type S struct{ a,b,c int }; type SS struct{ aa,bb,cc S }; type SA struct{ a,b,c [3]int }; ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test embedded fields of structs, including methods. package main type I interface { test1() int test2() int test3() int test4() int test5() i...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test 'for range' on arrays, slices, and maps. package main const size = 16 var a [size]byte var p []byte var m map[int]byte func f(k int) byte { ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test shift. package main var ians [18]int; var uans [18]uint; var pass string; func testi(i int, t1,t2,t3 int) { n := ((t1*3) + t2)*2 + t3; if i...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test basic operation of finalizers. package main import ( "runtime" "time" ) const N = 250 type A struct { b *B n int } type B struct { n i...
Go
// [ "$GOOS" == windows ] || // ($G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out) // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that a program can survive SIGCHLD. package main import ...
Go
// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test map declarations of many types, including erroneous ones. // Does not compile. package main func main() {} type v bool var ( // val...
Go
// run // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test that zero division causes a panic. package main import ( "fmt" "math" "runtime" "strings" ) type ErrorTest struct { name string fn fu...
Go
// skip # used by import3 // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Various declarations of exported variables and functions. // Imported by import3.go. package p var C1 chan <- chan int = (chan<...
Go
// errorcheck // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that import conflicts are detected by the compiler. // Does not compile. package main import "bufio" // GCCGO_ERROR "previous|not use...
Go
// skip // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file is compiled and then imported by ddd3.go. package ddd func Sum(args ...int) int { s := 0 for _, v := range args { s += v } return...
Go
// errorcheck // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that erroneous labels are caught by the compiler. // This set is caught by pass 1. // Does not compile. package main var x int func...
Go
// errorcheck // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Verify that incorrect invocations of the complex predeclared function are detected. // Does not compile. package main var ( f32 float32 f6...
Go
// run // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test the run-time behavior of escape analysis-related optimizations. package main func main() { test1() } func test1() { check1(0) check1(1) ...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test close(c), receive of closed channel. // // TODO(rsc): Doesn't check behavior of close(c) when there // are blocked senders/receivers. package m...
Go
// errchk -0 $G -m -l $D/$F.go // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test, using compiler diagnostic flags, that bounds check elimination // is eliminating the correct checks. package foo var...
Go
// run // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test floating-point comparison involving NaN. package main import "math" type floatTest struct { name string expr bool want bool } var nan flo...
Go