Skip to content

Add diffing support to bash tests #531

Closed
@MichaelDimmitt

Description

@MichaelDimmitt

Diffing is easy to attain in bats
If you add printDiff to every function.
It will only show the output if the test fails.

curious if @IsaacG has thoughts.

by changing

@test "a name given" {
  [[ $BATS_RUN_SKIPPED == true  ]] || skip
  run two_fer Alice
  [[ $status -eq 0 ]]
  [[ $output == "One for Alice, one for me." ]]
}
printDiff(){
  echo output;
  echo "$output";
  echo ;
  echo expected;
  echo "$expected;
}

@test "a name given" {
  [[ $BATS_RUN_SKIPPED == true  ]] || skip
  run two_fer Alice

  expected=$(cat <<-END
One for Alice, one for me.
END
  )

  printDiff
  [[ $status -eq 0 ]]
  [[ "$output" ==  "$expected" ]]
}

This actually just saved me on a project.
And I am sourcing the scripts like libs as is proposed in the pending pr
#373

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions