code
stringlengths
10
1.34M
language
stringclasses
1 value
// 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 that error messages say what the source file says // (uint8 vs byte, int32 vs. rune). // Does not compile. package main import ( "fmt...
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 var x = x + 1 works. package main func main() { var x int = 1 if x != 1 { print("found ", x, ", expected 1\n") panic("fail") } { var...
Go
// build // 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 general operation by solving a peg solitaire game. // A version of this is in the Go playground. // Don't run it - produces too much output. ...
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 behavior of closures. package main import "runtime" var c = make(chan int) func check(a []int) { for i := 0; i < len(a); i++ { n := <...
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 channel operations that test for blocking. // Use several sizes and types of operands. package main import "runtime" import "time" func i32re...
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 making channels of a zero-sized type. package main func main() { _ = make(chan [0]byte) _ = make(chan [0]byte, 1) _ = make(chan struct{}) ...
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 a select statement proceeds when a value is ready. package main func f() *int { println("BUG: called f") return new(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 concurrency primitives: power series. // Like powser1.go but uses channels of interfaces. // Has not been cleaned up as much as powser1.go, to ...
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 that unbuffered channels act as pure fifos. package main import "os" const N = 10 func AsynchFifo() { ch := make(chan int, N) for i := 0; ...
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 various parsing cases that are a little // different now that send is a statement, not a expression. package main func main() { chanchan() ...
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 situation in which two cases of a select can // both end up running. See http://codereview.appspot.com/180068. package main import ( "fla...
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. // Test various correct and incorrect permutations of send-only, // receive-only, and bidirectional channels. // Does not compile. package main ...
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 the semantics of the select statement // for basic empty/non-empty cases. package main import "time" const always = "function did not" const ...
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 selects do not consume undue memory. package main import "runtime" func sender(c chan int, n int) { for i := 0; i < n; i++ { c <- 1 ...
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 select when discarding a value. package main import "runtime" func recv1(c <-chan int) { <-c } func recv2(c <-chan int) { select { case ...
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 for select: Issue 2075 // A bug in select corrupts channel queues of failed cases // if there are multiple waiters on those channels and the //...
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. // Torture test for goroutines. // Make a lot of goroutines, threaded together, and tear them down cleanly. package main import ( "os" "strconv" ) ...
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 concurrency primitives: prime sieve of Eratosthenes. // Generate primes up to 100 using channels, checking the results. // This sieve is Eratos...
Go
// runoutput // 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. // Generate test of channel operations and simple selects. // The output of this program is compiled and run to do the // actual test. // Each 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 concurrency primitives: classical inefficient concurrent prime sieve. // Generate primes up to 100 using channels, checking the results. // Thi...
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 select. package main var counter uint var shift uint func GetValue() uint { counter++ return 1 << shift } func Send(a, b chan uint)...
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 concurrency primitives: power series. // Power series package // A power series is a channel, along which flow rational // coefficients. A den...
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 recovering from runtime errors. package main import ( "runtime" "strings" ) var didbug bool func bug() { if didbug { return } printl...
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 literal syntax. package main import "os" func main() { s := 0 + 123 + 0123 + 0000 + 0x0 + 0x123 + 0X0 + 0X123 if s !...
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 divide corner cases. package main import "fmt" func f8(x, y, q, r int8) { if t := x / y; t != q { fmt.Printf("%d/%d = %d, want %d\n", x, ...
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 equality and inequality operations. package main import "unsafe" var global bool func use(b bool) { global = b } func stringptr(s string) ui...
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 type switches, including chans, maps etc. package main import "os" const ( Bool = iota Int Float String Struct Chan Array Map ...
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 goto semantics. // Does not compile. // // Each test is in a separate function just so that if the // compiler stops processing after ...
Go
// compile // 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 top-level parenthesized declarations can be empty. // Compiles but does not run. package P import ( ) const ( ) var ( ) type ( )
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 type switches are caught be the compiler. // Issue 2700, among other things. // Does not compile. package main import ...
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 stack splitting code. // Try to tickle stack splitting bugs by doing // go, defer, and closure calls at different stack depths. package main 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 maps, almost exhaustively. package main import ( "fmt" "math" "strconv" "time" ) const count = 100 func P(a []string) string { s := "{"...
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 correct short declarations and redeclarations. package main func f1() int { return 1 } func f2() (float32, int) { r...
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. package main fmt.Printf("hello") // ERROR "non-declaration statement outside function body|expected declaration" func main() { } x++ // ERROR...
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. package main func main() { // ERROR "unexpected semicolon or newline before .?{.?"
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. package main import ( "io", // ERROR "unexpected comma" "os" )
Go
// errorcheck // 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 main var a = []int{ 3 // ERROR "need trailing comma before newline in composite literal" }
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. package main func main() { switch main() := interface{}(nil).(type) { // ERROR "invalid variable name" default: } }
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. package main func main() { if x; y // ERROR "unexpected semicolon or newline before .?{.?|undefined" { z // GCCGO_ERROR "undefined"
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. package main type xyz struct { ch chan } // ERROR "unexpected .*}.* in channel type" func Foo(y chan) { // ERROR "unexpected .*\).* in cha...
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. package main type T interface { f, g () // ERROR "name list not allowed in interface type" }
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. package main func main() { for x; y; z // ERROR "unexpected semicolon or newline before .?{.?|undefined" { z // GCCGO_ERROR "undefined"
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. package main func main() { if x { } // GCCGO_ERROR "undefined" else { } // ERROR "unexpected semicolon or newline before .?else.?" }
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. package main var c chan int var v int func main() { if c <- v { // ERROR "send statement.*value.*select" } } var _ = c <- v // ERROR "send ...
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. package main func main() { var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement|expected ';' or '}' or newline"
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. package main func main() { for x // GCCGO_ERROR "undefined" { // ERROR "unexpected semicolon or newline before .?{.?" z // GCCGO_ERROR "u...
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. package main func main() { if true { } else ; // ERROR "else must be followed by if or statement block|expected .if. or .{." }
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. package main var x map[string]string{"a":"b"} // ERROR "unexpected { at end of statement|expected ';' or newline after top level declaration" ...
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. package main func main() { for var x = 0; x < 10; x++ { // ERROR "var declaration not allowed in for initializer"
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. package main type T // ERROR "unexpected semicolon or newline in type declaration" {
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. package main func main() { switch x; y // ERROR "unexpected semicolon or newline before .?{.?|undefined" { z
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. package main func x() { } func main() { if { // ERROR "missing condition" } if x(); { // ERROR "missing condition" } }
Go
// compile // 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 function signatures. // Compiled but not run. package main type t1 int type t2 int type t3 int func f1(t1, t2, t3) func f2(t1, t2, t3 boo...
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. // Test that even if a file imports runtime, // it cannot get at the low-level runtime definitions // known to the compiler. For normal package...
Go
// $G $D/$F.go && $L -X main.tbd hello $F.$A && ./$A.out // 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 the -X facility of the gc linker (6l etc.). package main var tbd string func main() { if ...
Go
// run // 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 conversion from non-interface types to the empty interface. package main type J interface { Method() } type ( U16 uint16 U32 uint32 U64...
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. // Semi-exhaustive test for the append predeclared function. package main import ( "fmt" "reflect" ) func verify(name string, result, expected int...
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 2. That's why this file is label1.go. // Does not com...
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 len constants and non-constants, http://golang.org/issue/3244. package main var b struct { a[10]int } var m map[string][20]int var s [][30]...
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 that basic operations on named types are valid // and preserve the type. package main type Array [10]byte type Bool bool type Chan chan int t...
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 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
// 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