github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0179.yml (about)

     1  doc_meta: |
     2    folder: error_handling
     3    title: last_result pass through block func
     4    head: |
     5      Even though calling a block func is same as calling an internal or external call func, the regular vars override from current task to the block, it means this will apply to last_result, so that the the last_result will be the value from parent called
     6  
     7      This is to demo that the correct behavior should be that last_result will be an exception of the rule so that called func could get correct shell execution result
     8  
     9      Be cautious that when you register a name the shell execution result, do not use the duplicated name in the block func, as the rule will make the caller's var available in the funcs of the block, this will confuse you but it is correct.
    10  
    11    sections:
    12      - title: Demo
    13        log: yes
    14  
    15  tasks:
    16    -
    17      name: task
    18      task:
    19        -
    20          func: shell
    21          do: echo hello
    22  
    23        - func: cmd
    24          do:
    25            - name: print
    26              cmd: '{{.last_result.Output}}'
    27  
    28        - func: block
    29          do:
    30            -
    31              func: shell
    32              do: echo world
    33  
    34            - func: cmd
    35              do:
    36                - name: print
    37                  cmd: '{{.last_result.Output}}'
    38  
    39                -
    40                  name: assert
    41                  cmd:
    42                    - '{{eq .last_result.Output "world" }}'
    43  
    44        - func: cmd
    45          desc: after the block func call
    46          do:
    47            - name: print
    48              cmd: '{{.last_result.Output}}'
    49  
    50            -
    51              name: assert
    52              cmd:
    53                - '{{eq .last_result.Output "world" }}'