sstephenson / bats

Bash Automated Testing System
MIT License
7.13k stars 517 forks source link

Support for command that return non-zero exit status #251

Open onknows opened 6 years ago

onknows commented 6 years ago

I have a command that returns exit status 1. I want to test this but I noticed that Bats expects exit status to be zero. Else it stops executions. This is nice feature to add I think.

tsikerdekis commented 6 years ago

Perhaps an override command could be added to ignore exit statuses?

trnubo commented 6 years ago

I'm only new to bats but I think this is already the case

root@1e8afabe18ae:~# cat false.bats 
#!/usr/bin/env bats

@test "non-zero exit - false" {
  run false
  [ ${status} -ne 0 ]
}

@test "non-zero exit - exit 5" {
  run exit 5
  [ ${status} -eq 5 ]
}
root@1e8afabe18ae:~# bats false.bats 
 ✓ non-zero exit - false
 ✓ non-zero exit - exit 5

2 tests, 0 failures
root@1e8afabe18ae:~# false; echo $?
1
root@1e8afabe18ae:~# bash -c 'exit 5'; echo $?
5
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.