(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:CURRENT_DIR)
          op: Equal
          rhs: 
            {
              (DQ 
                (CommandSubPart
                  command_list: 
                    (CommandList
                      children: [
                        (AndOr
                          children: [
                            (C {(cd)} 
                              {
                                (DQ 
                                  (CommandSubPart
                                    command_list: 
                                      (CommandList
                                        children: [
                                          (C {(dirname)} 
                                            {
                                              (DQ 
                                                (BracedVarSub
                                                  token: <VSub_Name BASH_SOURCE>
                                                  bracket_op: 
                                                    (ArrayIndex
                                                      expr: (ArithWord w:{(Lit_Digits 0)})
                                                    )
                                                  spids: [68 73]
                                                )
                                              )
                                            }
                                          )
                                        ]
                                      )
                                    left_token: <Left_CommandSub "$(">
                                    spids: [64 75]
                                  )
                                )
                              }
                            )
                            (C {(pwd)})
                          ]
                          op_id: Op_DAmp
                        )
                      ]
                    )
                  left_token: <Left_CommandSub "$(">
                  spids: [60 81]
                )
              )
            }
          spids: [58]
        )
      ]
      spids: [58]
    )
    (AndOr
      children: [
        (C {(source)} {(DQ (${ VSub_Name CURRENT_DIR) (/../integration_test_setup.sh))})
        (BraceGroup
          children: [
            (Sentence
              child: 
                (SimpleCommand
                  words: [{(echo)} {(DQ ("integration_test_setup.sh not found!"))}]
                  redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[105])]
                )
              terminator: <Op_Semi ";">
            )
            (Sentence child:(C {(exit)} {(1)}) terminator:<Op_Semi ";">)
          ]
          spids: [97]
        )
      ]
      op_id: Op_DPipe
    )
    (C {(set)} {(-e)})
    (FuncDef
      name: set_up
      body: 
        (BraceGroup
          children: [
            (C {(mkdir)} {(-p)} {(pkg)})
            (SimpleCommand
              words: [{(cat)}]
              redirects: [
                (Redir op_id:Redir_Great fd:-1 arg_word:{(pkg/BUILD)} spids:[144])
                (HereDoc
                  op_id: Redir_DLess
                  fd: -1
                  body: 
                    {
                      (DQ ("genrule(\n") ("  name = ") (Right_DoubleQuote "\"") (showenv) 
                        (Right_DoubleQuote "\"") (",\n") ("  outs = [") (Right_DoubleQuote "\"") (env.txt) (Right_DoubleQuote "\"") ("],\n") ("  cmd = ") 
                        (Right_DoubleQuote "\"") ("env | sort > ") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) 
                        (EscapedLiteralPart token:<Lit_EscapedChar "\\$">) ("@") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (Right_DoubleQuote "\"") ("\n") (")\n")
                      )
                    }
                  do_expansion: True
                  here_end: EOF
                  was_filled: True
                  spids: [148]
                )
              ]
            )
          ]
          spids: [132]
        )
      spids: [126 131]
    )
    (FuncDef
      name: test_simple
      body: 
        (BraceGroup
          children: [
            (C {(export)} {(Lit_VarLike "FOO=") (baz)})
            (AndOr
              children: [
                (C {(bazel)} {(build)} {(--action_env) (Lit_Other "=") (Lit_VarLike "FOO=") (bar)} 
                  {(pkg) (Lit_Other ":") (showenv)}
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (SimpleCommand
              words: [
                {(cat)}
                {
                  (CommandSubPart
                    command_list: 
                      (CommandList
                        children: [(C {(bazel)} {(info)} {(${ VSub_Name PRODUCT_NAME) (-genfiles)})]
                      )
                    left_token: <Left_Backtick "`">
                    spids: [224 233]
                  ) (/pkg/env.txt)
                }
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: -1
                  arg_word: {($ VSub_Name "$TEST_log")}
                  spids: [236]
                )
              ]
            )
            (C {(expect_log)} {(DQ ("FOO=bar"))})
          ]
          spids: [185]
        )
      spids: [179 184]
    )
    (FuncDef
      name: test_simple_latest_wins
      body: 
        (BraceGroup
          children: [
            (C {(export)} {(Lit_VarLike "FOO=") (environmentfoo)})
            (C {(export)} {(Lit_VarLike "BAR=") (environmentbar)})
            (AndOr
              children: [
                (C {(bazel)} {(build)} {(--action_env) (Lit_Other "=") (Lit_VarLike "FOO=") (foo)} 
                  {(--action_env) (Lit_Other "=") (Lit_VarLike "BAR=") (willbeoverridden)} {(--action_env) (Lit_Other "=") (Lit_VarLike "BAR=") (bar)} {(pkg) (Lit_Other ":") (showenv)}
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (SimpleCommand
              words: [
                {(cat)}
                {
                  (CommandSubPart
                    command_list: 
                      (CommandList
                        children: [(C {(bazel)} {(info)} {(${ VSub_Name PRODUCT_NAME) (-genfiles)})]
                      )
                    left_token: <Left_Backtick "`">
                    spids: [313 322]
                  ) (/pkg/env.txt)
                }
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: -1
                  arg_word: {($ VSub_Name "$TEST_log")}
                  spids: [325]
                )
              ]
            )
            (C {(expect_log)} {(DQ ("FOO=foo"))})
            (C {(expect_log)} {(DQ ("BAR=bar"))})
          ]
          spids: [256]
        )
      spids: [250 255]
    )
    (FuncDef
      name: test_client_env
      body: 
        (BraceGroup
          children: [
            (C {(export)} {(Lit_VarLike "FOO=") (startup_foo)})
            (C {(bazel)} {(clean)} {(--expunge)})
            (AndOr
              children: [
                (SimpleCommand
                  words: [{(bazel)} {(help)} {(build)}]
                  redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[374])]
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" help failed"))})
              ]
              op_id: Op_DPipe
            )
            (C {(export)} {(Lit_VarLike "FOO=") (client_foo)})
            (AndOr
              children: [
                (C {(bazel)} {(build)} {(--action_env) (Lit_Other "=") (FOO)} 
                  {(pkg) (Lit_Other ":") (showenv)}
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (SimpleCommand
              words: [
                {(cat)}
                {
                  (CommandSubPart
                    command_list: 
                      (CommandList
                        children: [(C {(bazel)} {(info)} {(${ VSub_Name PRODUCT_NAME) (-genfiles)})]
                      )
                    left_token: <Left_Backtick "`">
                    spids: [425 434]
                  ) (/pkg/env.txt)
                }
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: -1
                  arg_word: {($ VSub_Name "$TEST_log")}
                  spids: [437]
                )
              ]
            )
            (C {(expect_log)} {(DQ ("FOO=client_foo"))})
          ]
          spids: [352]
        )
      spids: [346 351]
    )
    (FuncDef
      name: test_redo_action
      body: 
        (BraceGroup
          children: [
            (C {(export)} {(Lit_VarLike "FOO=") (initial_foo)})
            (C {(export)} {(Lit_VarLike "UNRELATED=") (some_value)})
            (AndOr
              children: [
                (C {(bazel)} {(build)} {(--action_env) (Lit_Other "=") (FOO)} 
                  {(pkg) (Lit_Other ":") (showenv)}
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (SimpleCommand
              words: [
                {(cat)}
                {
                  (CommandSubPart
                    command_list: 
                      (CommandList
                        children: [(C {(bazel)} {(info)} {(${ VSub_Name PRODUCT_NAME) (-genfiles)})]
                      )
                    left_token: <Left_Backtick "`">
                    spids: [501 510]
                  ) (/pkg/env.txt)
                }
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: -1
                  arg_word: {($ VSub_Name "$TEST_log")}
                  spids: [513]
                )
              ]
            )
            (C {(expect_log)} {(DQ ("FOO=initial_foo"))})
            (C {(export)} {(Lit_VarLike "UNRELATED=") (some_other_value)})
            (AndOr
              children: [
                (SimpleCommand
                  words: [
                    {(bazel)}
                    {(build)}
                    {(--action_env) (Lit_Other "=") (FOO)}
                    {(-s)}
                    {(--experimental_ui)}
                    {(pkg) (Lit_Other ":") (showenv)}
                  ]
                  redirects: [
                    (Redir
                      op_id: Redir_Great
                      fd: 2
                      arg_word: {($ VSub_Name "$TEST_log")}
                      spids: [552]
                    )
                  ]
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (C {(expect_not_log)} {(SQ <"^SUBCOMMAND.*pkg:showenv">)})
            (C {(export)} {(Lit_VarLike "FOO=") (changed_foo)})
            (AndOr
              children: [
                (SimpleCommand
                  words: [
                    {(bazel)}
                    {(build)}
                    {(--action_env) (Lit_Other "=") (FOO)}
                    {(-s)}
                    {(--experimental_ui)}
                    {(pkg) (Lit_Other ":") (showenv)}
                  ]
                  redirects: [
                    (Redir
                      op_id: Redir_Great
                      fd: 2
                      arg_word: {($ VSub_Name "$TEST_log")}
                      spids: [604]
                    )
                  ]
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (C {(expect_log)} {(SQ <"^SUBCOMMAND.*pkg:showenv">)})
            (SimpleCommand
              words: [
                {(cat)}
                {
                  (CommandSubPart
                    command_list: 
                      (CommandList
                        children: [(C {(bazel)} {(info)} {(${ VSub_Name PRODUCT_NAME) (-genfiles)})]
                      )
                    left_token: <Left_Backtick "`">
                    spids: [631 640]
                  ) (/pkg/env.txt)
                }
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: -1
                  arg_word: {($ VSub_Name "$TEST_log")}
                  spids: [643]
                )
              ]
            )
            (C {(expect_log)} {(DQ ("FOO=changed_foo"))})
            (AndOr
              children: [
                (SimpleCommand
                  words: [
                    {(bazel)}
                    {(build)}
                    {(--action_env) (Lit_Other "=") (FOO)}
                    {(-s)}
                    {(--experimental_ui)}
                    {(pkg) (Lit_Other ":") (showenv)}
                  ]
                  redirects: [
                    (Redir
                      op_id: Redir_Great
                      fd: 2
                      arg_word: {($ VSub_Name "$TEST_log")}
                      spids: [676]
                    )
                  ]
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (C {(expect_not_log)} {(SQ <"^SUBCOMMAND.*pkg:showenv">)})
          ]
          spids: [457]
        )
      spids: [451 456]
    )
    (FuncDef
      name: test_latest_wins_arg
      body: 
        (BraceGroup
          children: [
            (C {(export)} {(Lit_VarLike "FOO=") (bar)})
            (C {(export)} {(Lit_VarLike "BAR=") (baz)})
            (AndOr
              children: [
                (C {(bazel)} {(build)} {(--action_env) (Lit_Other "=") (BAR)} 
                  {(--action_env) (Lit_Other "=") (FOO)} {(--action_env) (Lit_Other "=") (Lit_VarLike "FOO=") (foo)} {(pkg) (Lit_Other ":") (showenv)}
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (SimpleCommand
              words: [
                {(cat)}
                {
                  (CommandSubPart
                    command_list: 
                      (CommandList
                        children: [(C {(bazel)} {(info)} {(${ VSub_Name PRODUCT_NAME) (-genfiles)})]
                      )
                    left_token: <Left_Backtick "`">
                    spids: [762 771]
                  ) (/pkg/env.txt)
                }
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: -1
                  arg_word: {($ VSub_Name "$TEST_log")}
                  spids: [774]
                )
              ]
            )
            (C {(expect_log)} {(DQ ("FOO=foo"))})
            (C {(expect_log)} {(DQ ("BAR=baz"))})
            (C {(expect_not_log)} {(DQ ("FOO=bar"))})
          ]
          spids: [709]
        )
      spids: [703 708]
    )
    (FuncDef
      name: test_latest_wins_env
      body: 
        (BraceGroup
          children: [
            (C {(export)} {(Lit_VarLike "FOO=") (bar)})
            (C {(export)} {(Lit_VarLike "BAR=") (baz)})
            (AndOr
              children: [
                (C {(bazel)} {(build)} {(--action_env) (Lit_Other "=") (BAR)} 
                  {(--action_env) (Lit_Other "=") (Lit_VarLike "FOO=") (foo)} {(--action_env) (Lit_Other "=") (FOO)} {(pkg) (Lit_Other ":") (showenv)}
                )
                (C {(fail)} {(DQ (${ VSub_Name PRODUCT_NAME) (" build showenv failed"))})
              ]
              op_id: Op_DPipe
            )
            (SimpleCommand
              words: [
                {(cat)}
                {
                  (CommandSubPart
                    command_list: 
                      (CommandList
                        children: [(C {(bazel)} {(info)} {(${ VSub_Name PRODUCT_NAME) (-genfiles)})]
                      )
                    left_token: <Left_Backtick "`">
                    spids: [861 870]
                  ) (/pkg/env.txt)
                }
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: -1
                  arg_word: {($ VSub_Name "$TEST_log")}
                  spids: [873]
                )
              ]
            )
            (C {(expect_log)} {(DQ ("FOO=bar"))})
            (C {(expect_log)} {(DQ ("BAR=baz"))})
            (C {(expect_not_log)} {(DQ ("FOO=foo"))})
          ]
          spids: [808]
        )
      spids: [802 807]
    )
    (FuncDef
      name: test_env_freezing
      body: 
        (BraceGroup
          children: [
            (C {(add_to_bazelrc)} {(DQ ("build --action_env=FREEZE_TEST_FOO"))})
            (C {(add_to_bazelrc)} {(DQ ("build --action_env=FREEZE_TEST_BAR=is_fixed"))})
            (C {(add_to_bazelrc)} {(DQ ("build --action_env=FREEZE_TEST_BAZ=will_be_overridden"))})
            (C {(add_to_bazelrc)} {(DQ ("build --action_env=FREEZE_TEST_BUILD"))})
            (C {(export)} {(Lit_VarLike "FREEZE_TEST_FOO=") (client_foo)})
            (C {(export)} {(Lit_VarLike "FREEZE_TEST_BAR=") (client_bar)})
            (C {(export)} {(Lit_VarLike "FREEZE_TEST_BAZ=") (client_baz)})
            (C {(export)} {(Lit_VarLike "FREEZE_TEST_BUILD=") (client_build)})
            (SimpleCommand
              words: [
                {(bazel)}
                {(info)}
                {(--action_env) (Lit_Other "=") (FREEZE_TEST_BAZ)}
                {(client-env)}
              ]
              redirects: [
                (Redir
                  op_id: Redir_Great
                  fd: -1
                  arg_word: {($ VSub_Name "$TEST_log")}
                  spids: [974]
                )
              ]
            )
            (C {(expect_log)} {(DQ ("build --action_env=FREEZE_TEST_FOO=client_foo"))})
            (C {(expect_not_log)} {(DQ (FREEZE_TEST_BAR))})
            (C {(expect_log)} {(DQ ("build --action_env=FREEZE_TEST_BAZ=client_baz"))})
            (C {(expect_log)} {(DQ ("build --action_env=FREEZE_TEST_BUILD=client_build"))})
            (C {(rm)} {(-f)} {(.) (${ VSub_Name PRODUCT_NAME) (rc)})
          ]
          spids: [907]
        )
      spids: [901 906]
    )
    (C {(run_suite)} {(DQ ("Tests for bazel's handling of environment variables in actions"))})
  ]
)