The Go Programming Language

Text file doc/progs/run

     1	#!/usr/bin/env bash
     2	# Copyright 2009 The Go Authors. All rights reserved.
     3	# Use of this source code is governed by a BSD-style
     4	# license that can be found in the LICENSE file.
     5	
     6	set -e
     7	
     8	eval $(gomake --no-print-directory -f ../../src/Make.inc go-env)
     9	
    10	if [ -z "$O" ]; then
    11		echo 'missing $O - maybe no Make.$GOARCH?' 1>&2
    12		exit 1
    13	fi
    14	
    15	rm -f *.$O
    16	
    17	if [ "$GOOS" = "windows" ];then
    18		$GC -o file.8 file_windows.go
    19	else
    20		$GC file.go
    21	fi
    22	
    23	for i in \
    24		helloworld.go \
    25		helloworld3.go \
    26		echo.go \
    27		cat.go \
    28		cat_rot13.go \
    29		sum.go \
    30		sort.go \
    31		sortmain.go \
    32		print.go \
    33		print_string.go \
    34		sieve.go \
    35		sieve1.go \
    36		server1.go \
    37		strings.go \
    38	; do
    39		$GC $i
    40	done
    41	
    42	function testit {
    43		$LD $1.$O
    44		x=$(echo $(./$O.out $2 2>&1))  # extra echo canonicalizes
    45		if [ "$x" != "$3" ]
    46		then
    47			echo $1 failed: '"'$x'"' is not '"'$3'"'
    48		fi
    49	}
    50	
    51	function testitpipe {
    52		$LD $1.$O
    53		x=$(echo $(./$O.out | $2 2>&1))  # extra echo canonicalizes
    54		if [ "$x" != "$3" ]
    55		then
    56			echo $1 failed: '"'$x'"' is not '"'$3'"'
    57		fi
    58	}
    59	
    60	
    61	testit helloworld "" "Hello, world; or Καλημέρα κόσμε; or こんにちは 世界"
    62	testit helloworld3 "" "hello, world can't open file; err=no such file or directory"
    63	testit echo "hello, world" "hello, world"
    64	testit sum "" "6"
    65	testit strings "" ""
    66	
    67	alphabet=abcdefghijklmnopqrstuvwxyz
    68	rot13=nopqrstuvwxyzabcdefghijklm
    69	echo $alphabet | testit cat "" $alphabet
    70	echo $alphabet | testit cat_rot13 "--rot13" $rot13
    71	echo $rot13 | testit cat_rot13 "--rot13" $alphabet
    72	
    73	testit sortmain "" "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
    74	
    75	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]"
    76	testit print_string "" "77 Sunset Strip"
    77	
    78	testitpipe sieve "sed 10q" "2 3 5 7 11 13 17 19 23 29"
    79	testitpipe sieve "sed 10q" "2 3 5 7 11 13 17 19 23 29"
    80	
    81	# server hangs; don't run it, just compile it
    82	$GC server.go
    83	testit server1 "" ""
    84	
    85	rm -f $O.out *.$O

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.