Skip to content

$lines keep blank empty lines in $output  #224

@Sylvain303

Description

@Sylvain303

The bats code involved is also related to: #151

The faulty code is here

run() {
  local origFlags="$-"
  set +eET
  local origIFS="$IFS"
  output="$("$@" 2>&1)"
  status="$?"
  IFS=$'\n' lines=($output)
  IFS="$origIFS"
  set "-$origFlags"
}

Reproduce:

#!/bin/bash

usage() {
  cat << EOT
pipo

molo
EOT
}

@test "test lines with empty line" {
  run usage
  echo "$output" >> log
  num_lines=$(wc -l <<<"$output")
  [[ $num_lines -eq 3 ]]
  n=${#lines[@]}
  for i in $(seq 0 $((n - 1)))
  do
    echo "$i:${lines[$i]}" >> log
  done

  [[ ${lines[0]} == "pipo" ]]
  [[ ${lines[1]} == "" ]]
  [[ ${lines[2]} == "molo" ]]
  [[ $num_lines -eq ${#lines[@]} ]]
}

I suppose that fixing it will introduce some outside test failure based on this bugged behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Bash CodeEverything regarding the bash codePriority: HighBroken behavior in specific environments like in parallel mode or only on some operating systemsType: BugType: Enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions