github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/cmd/gno/env_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestEnvApp(t *testing.T) {
     9  	const (
    10  		testGnoRootEnv = "/faster/better/stronger"
    11  		testGnoHomeEnv = "/around/the/world"
    12  	)
    13  
    14  	t.Setenv("GNOROOT", testGnoRootEnv)
    15  	t.Setenv("GNOHOME", testGnoHomeEnv)
    16  	tc := []testMainCase{
    17  		// shell
    18  		{args: []string{"env", "foo"}, stdoutShouldBe: "\n"},
    19  		{args: []string{"env", "foo", "bar"}, stdoutShouldBe: "\n\n"},
    20  		{args: []string{"env", "GNOROOT"}, stdoutShouldBe: testGnoRootEnv + "\n"},
    21  		{args: []string{"env", "GNOHOME", "storm"}, stdoutShouldBe: testGnoHomeEnv + "\n\n"},
    22  		{args: []string{"env"}, stdoutShouldContain: fmt.Sprintf("GNOROOT=%q", testGnoRootEnv)},
    23  		{args: []string{"env"}, stdoutShouldContain: fmt.Sprintf("GNOHOME=%q", testGnoHomeEnv)},
    24  
    25  		// json
    26  		{args: []string{"env", "-json"}, stdoutShouldContain: fmt.Sprintf("\"GNOROOT\": %q", testGnoRootEnv)},
    27  		{args: []string{"env", "-json"}, stdoutShouldContain: fmt.Sprintf("\"GNOHOME\": %q", testGnoHomeEnv)},
    28  		{
    29  			args:           []string{"env", "-json", "GNOROOT"},
    30  			stdoutShouldBe: fmt.Sprintf("{\n\t\"GNOROOT\": %q\n}\n", testGnoRootEnv),
    31  		},
    32  		{
    33  			args:           []string{"env", "-json", "GNOROOT", "storm"},
    34  			stdoutShouldBe: fmt.Sprintf("{\n\t\"GNOROOT\": %q,\n\t\"storm\": \"\"\n}\n", testGnoRootEnv),
    35  		},
    36  		{
    37  			args:           []string{"env", "-json", "storm"},
    38  			stdoutShouldBe: "{\n\t\"storm\": \"\"\n}\n",
    39  		},
    40  	}
    41  
    42  	testMainCaseRun(t, tc)
    43  }