github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/testdata/env.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  )
     6  
     7  func main() {
     8  	// Check for environment variables (set by the test runner).
     9  	println("ENV1:", os.Getenv("ENV1"))
    10  	v, ok := os.LookupEnv("ENV2")
    11  	if !ok {
    12  		println("ENV2 not found")
    13  	}
    14  	println("ENV2:", v)
    15  
    16  	found := false
    17  	expected := "ENV1=" + os.Getenv("ENV1")
    18  	for _, envVar := range os.Environ() {
    19  		if envVar == expected {
    20  			found = true
    21  		}
    22  	}
    23  	if !found {
    24  		println("could not find " + expected + " in os.Environ()")
    25  	}
    26  
    27  	// Check for command line arguments.
    28  	// Argument 0 is skipped because it is the program name, which varies by
    29  	// test run.
    30  	println()
    31  	for _, arg := range os.Args[1:] {
    32  		println("arg:", arg)
    33  	}
    34  }