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

     1  doc_meta: |
     2    folder: vars
     3    title: var scope in callee
     4    head: |
     5      Showcase the var scope, how local var and global var are diffent and used in different context
     6  
     7    sections:
     8      - title: Demo
     9        log: yes
    10  
    11      - title: vars accessibility in call stack
    12        content: |
    13          Understanding of global vars scope in call stack
    14  
    15          global vars scope is not unique, it is a concept of relative scope for its call stack. within that call stack, all changes(new registered global vars) will be valid only for its own stack in that call func only
    16  
    17        refs:
    18          - title: show the problem
    19            link: ../../test-debug/c0107
    20  
    21      - title: taskScope
    22        content: |
    23          use taskScope
    24        refs:
    25          - title: taskScope
    26            link: ../../test-debug/c0108
    27  
    28  notes:
    29    goal:
    30      - to test the registered global var should be availabe in global context
    31  
    32  vars:
    33    tom: this is tom
    34  
    35  tasks:
    36    -
    37      name: task
    38      task:
    39        -
    40          func: call
    41          do: sub1
    42  
    43        -
    44          func: cmd
    45          desc: |
    46            check if hitom is available in global context
    47            it should be <no value> as hitom in sub1 is marked localOnly
    48          do:
    49            - name: print
    50              cmd: '{{.hitom}}'
    51  
    52        -
    53          func: call
    54          do: sub2
    55  
    56        -
    57          func: cmd
    58          desc: |
    59            check if hitom is available in global context
    60            though hitom was regiser as global var, but it was registered to its own call stack
    61            however this is only available in its own call stack global but not return and available to its parent var scope
    62          do:
    63            - name: print
    64              cmd: '{{.hitom}}'
    65  
    66    -
    67      name: sub1
    68      task:
    69        -
    70          func: cmd
    71          do:
    72  
    73            - name: reg
    74              cmd:
    75                name: hitom
    76                desc: by default hitom is registered in to global context
    77                value: 'hello, {{.tom}}'
    78              flags: [localOnly]
    79  
    80            - name: print
    81              cmd: '{{.hitom}}'
    82  
    83        -
    84          func: cmd
    85          do:
    86            - name: print
    87              desc: should be <no value> since it is marked localOnly
    88              cmd: '{{.hitom}}'
    89  
    90    -
    91      name: sub2
    92      task:
    93        -
    94          func: cmd
    95          do:
    96  
    97            - name: reg
    98              cmd:
    99                name: hitom
   100                desc: by default hitom is registered in to global context
   101                value: 'hello, {{.tom}}'
   102  
   103            - name: print
   104              cmd: '{{.hitom}}'
   105  
   106        -
   107          func: cmd
   108          do:
   109            - name: print
   110              desc: |
   111                by default hitom is accessible from global context, that's why it is accessiable cross func
   112                however this is only available in its own call stack global but not return and available to its parent var scope
   113              cmd: '{{.hitom}}'