sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 519 forks source link

[Feature request] Command line option to ignore tests failures when the exit code is computed #238

Open NBardelot opened 6 years ago

NBardelot commented 6 years ago

When one or more tests fail at the moment the bats command exits with an error code of 1. If there is a syntax error in the bats file, the behaviour is the same.

The feature would consist of a flag (for example "-i|--ignore-failures"), so that the exit code is 0 even if some tests fail, allowing the caller to differenciate between abnormal behaviour (exit code > 0) and tests failures (exit code = 0, but number of failures > 0 as printed in stdout).

NBardelot commented 6 years ago

Note:

For the moment in order to achieve the same goal I have to use the following wrapper script:

#!/bin/bash

clean_exit() {
    cat "$1"
    /bin/rm -f "$ERR_FILE" "$OUT_FILE"
    exit "$2"
}

OUT_FILE=$(mktemp)
ERR_FILE=$(mktemp)
bats $@ 1>"$OUT_FILE" 2>"$ERR_FILE"
RETVAL=$?
if [ $RETVAL -ne 0 ]
then
  if [ $(wc -l "$ERR_FILE" | awk '{ print $1 }') -gt 0 ]
  then
    clean_exit "$ERR_FILE" 1 # Abnormal error (probably a syntax error)!
  else
    clean_exit "$OUT_FILE" 2 # One or more tests fail
  fi
fi
clean_exit "$OUT_FILE" 0
Potherca commented 6 years ago

This project is no longer being actively maintained by its original auther (see https://github.com/sstephenson/bats/issues/236).

You might want to migrate to the community maintained fork bats-core and report your issue there.