name: "set -x"
cases:
  - name: "basic"
    stdin: |
      set -x

      ls

      for f in 1 2 3; do echo ${f}; done

      case 1 in
        1) echo "1";;
        *) echo "not";;
      esac

      while false; do
        echo body
      done

      newvar=$(echo "new")

      x=$((3 + 7))

      if [[ x == 10 && ! 0 ]]; then
        echo "Math checks"
      fi

      var="x"
      [[ ${var} && ${var//[[:space:]]/} ]]

      for ((i = 0; i < 3; i++)); do
        echo $i
      done

      ((x = 3)) || ((x = 4))

      override=value echo some_output

  - name: "sourced script"
    test_files:
      - path: script.sh
        contents: |
          echo "Entered script"
          for f in a b c; do echo $f; done
          echo "Exiting script"
    stdin: |
      set -x

      echo "About to source script"
      source script.sh
      echo "Back from script"

  - name: "functions"
    stdin: |
      set -x

      myfunc() {
        echo "In myfunc"
        for i in 1 2; do echo "i is $i"; done
      }

      echo "Before function call"
      myfunc
      echo "After function call"

  - name: "command line"
    args: ["-x", "script.sh"]
    test_files:
      - path: script.sh
        contents: |
          echo "In command line script"
          for n in x y z; do echo $n; done

  - name: "trap"
    known_failure: true # TODO(traps): review this
    stdin: |
      set -x

      trap 'echo "In trap"' DEBUG

      echo "Doing something"
