# Test that xtrace output is correctly generated

%prep
  mkdir xtrace.tmp && cd xtrace.tmp

  function xtf {
    local regression_test_dummy_variable
    print "$*"
  }
  echo 'print "$*"' > xt.in

%test

  set -x
  print 'Tracing: builtin'
  print 'Tracing: builtin 2>file' 2>xtrace.err
  cat <<<'Tracing: external'
  cat <<<'Tracing: external 2>file' 2>>xtrace.err
  ( print 'Tracing: ( builtin )' )
  ( print 'Tracing: ( builtin ) 2>file' ) 2>>xtrace.err
  ( cat <<<'Tracing: ( external )' )
  ( cat <<<'Tracing: ( external ) 2>file' ) 2>>xtrace.err
  { print 'Tracing: { builtin }' }
  { print 'Tracing: { builtin } 2>file' } 2>>xtrace.err
  { cat <<<'Tracing: { external }' }
  { cat <<<'Tracing: { external } 2>file' } 2>>xtrace.err
  repeat 1 do print 'Tracing: do builtin done'; done
  repeat 1 do print 'Tracing: do builtin done 2>file'; done 2>>xtrace.err
  repeat 1 do cat <<<'Tracing: do external done'; done
  repeat 1 do cat <<<'Tracing: do external done 2>file'; done 2>>xtrace.err
  xtf 'Tracing: function'
  xtf 'Tracing: function 2>file' 2>>xtrace.err
  . ./xt.in 'Tracing: source'
  . ./xt.in 'Tracing: source 2>file' 2>>xtrace.err
  set +x
  cat xtrace.err
0:xtrace with and without redirection
>Tracing: builtin
>Tracing: builtin 2>file
>Tracing: external
>Tracing: external 2>file
>Tracing: ( builtin )
>Tracing: ( builtin ) 2>file
>Tracing: ( external )
>Tracing: ( external ) 2>file
>Tracing: { builtin }
>Tracing: { builtin } 2>file
>Tracing: { external }
>Tracing: { external } 2>file
>Tracing: do builtin done
>Tracing: do builtin done 2>file
>Tracing: do external done
>Tracing: do external done 2>file
>Tracing: function
>Tracing: function 2>file
>Tracing: source
>Tracing: source 2>file
>+(eval):7> print Tracing: ( builtin ) 2>file
>+(eval):9> cat
>+(eval):11> print Tracing: { builtin } 2>file
>+(eval):13> cat
>+(eval):15> print Tracing: do builtin done 2>file
>+(eval):17> cat
?+(eval):2> print Tracing: builtin
?+(eval):3> print Tracing: builtin 2>file
?+(eval):4> cat
?+(eval):5> cat
?+(eval):6> print Tracing: ( builtin )
?+(eval):8> cat
?+(eval):10> print Tracing: { builtin }
?+(eval):12> cat
?+(eval):14> print Tracing: do builtin done
?+(eval):16> cat
?+(eval):18> xtf Tracing: function
?+xtf:1> local regression_test_dummy_variable
?+xtf:2> print Tracing: function
?+(eval):19> xtf Tracing: function 2>file
?+xtf:1> local regression_test_dummy_variable
?+xtf:2> print Tracing: function 2>file
?+(eval):20> . ./xt.in Tracing: source
?+./xt.in:1> print Tracing: source
?+(eval):21> . ./xt.in Tracing: source 2>file
?+./xt.in:1> print Tracing: source 2>file
?+(eval):22> set +x

 typeset -ft xtf
 xtf 'Tracing: function'
0:
>Tracing: function
?+xtf:1> local regression_test_dummy_variable
?+xtf:2> print Tracing: function
