echo $alphabet | testit cat_rot13 "--rot13" $rot13
echo $rot13 | testit cat_rot13 "--rot13" $alphabet
-testit sortmain "" "Sunday Monday Tuesday Thursday Friday"
+testit sortmain "" "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
testit print "" "18446744073709551615 -1 18446744073709551615 {77 Sunset Strip} [1 2 3 4] 18446744073709551615 {77 Sunset Strip} [1 2 3 4] 18446744073709551615 {77 Sunset Strip} [1 2 3 4]"
testit print_string "" "77 Sunset Strip"
Thursday := day{ 4, "THU", "Thursday" };
Friday := day{ 5, "FRI", "Friday" };
Saturday := day{ 6, "SAT", "Saturday" };
- data := []*day{&Tuesday, &Thursday, &Sunday, &Monday, &Friday};
+ data := []*day{&Tuesday, &Thursday, &Wednesday, &Sunday, &Monday, &Friday, &Saturday};
a := dayArray{data};
sort.Sort(&a);
if !sort.IsSorted(&a) {
func (tr *Reader) skipUnread() {
nr := tr.nb + tr.pad; // number of bytes to skip
- var n int64;
if sr, ok := tr.r.(io.Seeker); ok {
- n, tr.err = sr.Seek(nr, 1);
+ _, tr.err = sr.Seek(nr, 1);
} else {
- n, tr.err = io.Copyn(tr.r, ignoreWriter{}, nr);
+ _, tr.err = io.Copyn(tr.r, ignoreWriter{}, nr);
}
tr.nb, tr.pad = 0, 0;
}
func (tr *Reader) readHeader() *Header {
header := make([]byte, blockSize);
- var n int;
- if n, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
+ if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
return nil
}
// Two blocks of zero bytes marks the end of the archive.
if bytes.Equal(header, zeroBlock[0:blockSize]) {
- if n, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
+ if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
return nil
}
if !bytes.Equal(header, zeroBlock[0:blockSize]) {
s := slicer(header);
// TODO(dsymonds): handle names longer than 100 chars
- nr := bytes.Copy(s.next(100), strings.Bytes(hdr.Name));
+ bytes.Copy(s.next(100), strings.Bytes(hdr.Name));
tw.octal(s.next(8), hdr.Mode); // 100:108
tw.octal(s.next(8), hdr.Uid); // 108:116
return tw.err
}
- var n int;
- n, tw.err = tw.w.Write(header);
+ _, tw.err = tw.w.Write(header);
return tw.err
}
// trailer: two zero blocks
for i := 0; i < 2; i++ {
- var n int;
- n, tw.err = tw.w.Write(zeroBlock);
+ _, tw.err = tw.w.Write(zeroBlock);
if tw.err != nil {
break
}
func TestEncoderBuffering(t *testing.T) {
input := strings.Bytes(bigtest.decoded);
for bs := 1; bs <= 12; bs++ {
- buf := make([]byte, bs);
bb := &bytes.Buffer{};
encoder := NewEncoder(StdEncoding, bb);
for pos := 0; pos < len(input); pos += bs {
n = len(s);
}
a := make([][]byte, n);
- var size, rune int;
+ var size int;
na := 0;
for len(s) > 0 {
if na+1 >= n {
na++;
break
}
- rune, size = utf8.DecodeRune(s);
+ _, size = utf8.DecodeRune(s);
a[na] = s[0:size];
s = s[size:len(s)];
na++;
return err;
}
data := make([]byte, n);
- var nn int;
- if nn, err = io.ReadFull(z.r, data); err != nil {
+ if _, err = io.ReadFull(z.r, data); err != nil {
return err;
}
if save {
s10 := r10.Move(6);
sum10 := sumN(10);
- sum6 := sumN(6);
verify(t, r10, 10, sum10);
verify(t, s10, 10, sum10);
func (p *parser) parseString() string {
s := "";
if p.tok == token.STRING {
- var err os.Error;
- s, err = strconv.Unquote(string(p.lit));
+ s, _ = strconv.Unquote(string(p.lit));
// Unquote may fail with an error, but only if the scanner found
// an illegal string in the first place. In this case the error
// has already been reported.
pos := p.pos;
value := "";
if p.tok == token.STRING {
- var err os.Error;
- value, err = strconv.Unquote(string(p.lit));
+ value, _ = strconv.Unquote(string(p.lit));
// Unquote may fail with an error, but only if the scanner found
// an illegal string in the first place. In this case the error
// has already been reported.
"@ @ @" // original file, line 1 again
;
- var s Scanner;
v := NewErrorVector();
nerrors := Tokenize("File1", strings.Bytes(src), v, 0,
func (pos token.Position, tok token.Token, litb []byte) bool {
// Test basic encode/decode routines for signed integers
func TestIntCodec(t *testing.T) {
- var b = new(bytes.Buffer);
for u := uint64(0); ; u = (u+1) * 7 {
// Do positive and negative values
i := int64(u);
// int16
{
b.Reset();
- v := int16(17);
- pv := &v;
- ppv := &pv;
data := struct { a int16 } { 17 };
instr := &encInstr{ encInt16, 6, 0, 0 };
state := newencoderState(b);
dec.state.b = bytes.NewBuffer(dec.buf[0:nbytes]);
// Read the data
- var n int;
- n, dec.state.err = io.ReadFull(dec.r, dec.buf[0:nbytes]);
+ _, dec.state.err = io.ReadFull(dec.r, dec.buf[0:nbytes]);
if dec.state.err != nil {
if dec.state.err == os.EOF {
dec.state.err = io.ErrUnexpectedEOF;
func TestArrayType(t *testing.T) {
var a3 [3]int;
a3int := getTypeUnlocked("foo", reflect.Typeof(a3));
- var newa3 [3]int;
newa3int := getTypeUnlocked("bar", reflect.Typeof(a3));
if a3int != newa3int {
t.Errorf("second registration of [3]int creates new type");
if cr.n == 0 && cr.err == nil {
// end of chunk (CRLF)
b := make([]byte, 2);
- var nb int;
- if nb, cr.err = io.ReadFull(cr.r, b); cr.err == nil {
+ if _, cr.err = io.ReadFull(cr.r, b); cr.err == nil {
if b[0] != '\r' || b[1] != '\n' {
cr.err = os.NewError("malformed chunked encoding");
}
}
func TestQuery(t *testing.T) {
- var err os.Error;
req := &Request{ Method: "GET" };
- req.Url, err = ParseURL("http://www.google.com/search?q=foo&q=bar");
+ req.Url, _ = ParseURL("http://www.google.com/search?q=foo&q=bar");
if q := req.FormValue("q"); q != "foo" {
t.Errorf(`req.FormValue("q") = %q, want "foo"`, q);
}
// If StringToJson encounters a syntax error, it returns with
// ok set to false and errtok set to a fragment of the offending syntax.
func StringToJson(s string) (json Json, ok bool, errtok string) {
- var errindx int;
var j Json;
b := new(_JsonBuilder);
b.ptr = &j;
- ok, errindx, errtok = Parse(s, b);
+ ok, _, errtok = Parse(s, b);
if !ok {
return nil, false, errtok
}
// On a syntax error, it returns with ok set to false and errtok
// set to the offending token.
func Unmarshal(s string, val interface{}) (ok bool, errtok string) {
- var errindx int;
- var val1 interface{};
b := &_StructBuilder{ reflect.NewValue(val) };
- ok, errindx, errtok = Parse(s, b);
+ ok, _, errtok = Parse(s, b);
if !ok {
return false, errtok
}
rname += ".";
}
// Can try as ordinary name.
- var dnserr *DNSError;
addrs, err = tryOneName(cfg, rname);
if err == nil {
cname = rname;
if rname[len(rname)-1] != '.' {
rname += "."
}
- var dnserr *DNSError;
addrs, err = tryOneName(cfg, rname);
if err == nil {
cname = rname;
// Allow reuse of recently-used addresses.
syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1);
- var r int64;
if la != nil {
e = syscall.Bind(s, la);
if e != 0 {
// General algorithm: find name in parent
// and then find name of parent. Each iteration
// adds /name to the beginning of pwd.
- elem := make([]string, 0, 16);
pwd = "";
for parent := "..";; parent = "../" + parent {
if len(parent) >= 1024 { // Sanity check
// in the final slash-separated element of path;
// it is empty if there is no dot.
func Ext(path string) string {
- dot := -1;
for i := len(path)-1; i >= 0 && path[i] != '/'; i-- {
if path[i] == '.' {
return path[i:len(path)];
return str;
case *MapValue:
t := typ.(*MapType);
- v := val;
str = t.String();
str += "{";
str += "<can't iterate on maps>";
// TODO: This will have to go away when
// the new gc goes in.
func memmove(adst, asrc addr, n uintptr) {
- var p uintptr; // dummy for sizeof
dst := uintptr(adst);
src := uintptr(asrc);
switch {
panic("recv on send-only channel");
}
ch := *(**byte)(v.addr);
- newval := MakeZero(t.Elem());
x := MakeZero(t.Elem());
chanrecv(ch, (*byte)(x.getAddr()), b);
return x;
// after a previous match, so ignore it.
accept = false;
}
- var rune, width int;
+ var width int;
if b == nil {
- rune, width = utf8.DecodeRuneInString(s[pos:end]);
+ _, width = utf8.DecodeRuneInString(s[pos:end]);
} else {
- rune, width = utf8.DecodeRune(b[pos:end]);
+ _, width = utf8.DecodeRune(b[pos:end]);
}
if width > 0 {
pos += width;
if client.shutdown != nil {
c.Error = client.shutdown;
client.mutex.Unlock();
- doNotBlock := c.Done <- c;
+ _ = c.Done <- c; // do not block
return;
}
c.seq = client.seq;
c.Error = os.ErrorString(response.Error);
// We don't want to block here. It is the caller's responsibility to make
// sure the channel has enough buffer space. See comment in Go().
- doNotBlock := c.Done <- c;
+ _ = c.Done <- c; // do not block
}
// Terminate pending calls.
client.mutex.Lock();
client.shutdown = err;
for seq, call := range client.pending {
call.Error = err;
- doNotBlock := call.Done <- call;
+ _ = call.Done <- call; // do not block
}
client.mutex.Unlock();
log.Stderr("client protocol error:", err);
c.Done = done;
if client.shutdown != nil {
c.Error = client.shutdown;
- doNotBlock := c.Done <- c;
+ _ = c.Done <- c; // do not block
return c;
}
client.send(c);
sendResponse(sending, req, invalidRequest, enc, s);
continue;
}
- method := mtype.method;
// Decode the argument value.
argv := _new(mtype.argType);
replyv := _new(mtype.replyType);
}
func TestDecimalShift(t *testing.T) {
- ok := true;
for i := 0; i < len(shifttests); i++ {
test := &shifttests[i];
s := NewDecimal(test.i).Shift(test.shift).String();
(pid int, err int)
{
var p [2]int;
- var r1 int;
var n int;
var err1 uintptr;
var wstatus WaitStatus;
if err = Pipe(&p); err != 0 {
goto error;
}
- var val int;
- if val, err = fcntl(p[0], F_SETFD, FD_CLOEXEC); err != 0 {
+ if _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC); err != 0 {
goto error;
}
- if val, err = fcntl(p[1], F_SETFD, FD_CLOEXEC); err != 0 {
+ if _, err = fcntl(p[1], F_SETFD, FD_CLOEXEC); err != 0 {
goto error;
}
// of gotest.
func Main(tests []Test) {
flag.Parse();
- args := flag.Args();
ok := true;
if len(tests) == 0 {
println("testing: warning: no tests to run");
// }
func ticker(ns int64, c chan int64) {
- var tv syscall.Timeval;
now := Nanoseconds();
when := now;
for {
Sleep(when - now);
now = Nanoseconds();
c <- now;
+ if closed(c) {
+ return;
+ }
}
}
if p = d.read(16); len(p) != 16 || p[0] != 0 && p[0] != '2' {
return nil, false
}
- vers := p[0];
// six big-endian 32-bit integers:
// number of UTC/local indicators
// $TZ="foo" means use /usr/share/zoneinfo/foo.
tz, err := os.Getenverror("TZ");
- var ok bool;
switch {
case err == os.ENOENV:
- zones, ok = readinfofile("/etc/localtime");
+ zones, _ = readinfofile("/etc/localtime");
case len(tz) > 0:
- zones, ok = readinfofile(zoneDir + tz);
+ zones, _ = readinfofile(zoneDir + tz);
case len(tz) == 0:
// do nothing: use UTC
}
// DecodeRune unpacks the first UTF-8 encoding in p and returns the rune and its width in bytes.
func DecodeRune(p []byte) (rune, size int) {
- var short bool;
- rune, size, short = decodeRuneInternal(p);
+ rune, size, _ = decodeRuneInternal(p);
return;
}
// DecodeRuneInString is like DecodeRune but its input is a string.
func DecodeRuneInString(s string) (rune, size int) {
- var short bool;
- rune, size, short = decodeRuneInStringInternal(s);
+ rune, size, _ = decodeRuneInStringInternal(s);
return;
}
func main() {
in = bufio.NewReader(os.Stdin);
- buf := new(bytes.Buffer);
three := strings.Bytes(">THREE ");
for {
line, err := in.ReadSlice('\n');
func countMatches(pat string, bytes []byte) int {
re := compile(pat);
n := 0;
- pos := 0;
for {
e := re.Execute(bytes);
if len(e) == 0 {