kward / shunit2

shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does error message of assertNotContains end with "Found"?

gqqnbig opened this issue · comments

commented

test.sh

#!/bin/bash

testWhenDiskQuotaNotEnabled() {
    assertNotContains "Something" "Hello world" "world"
}
# shunit2 test.sh
testWhenDiskQuotaNotEnabled
ASSERT:Something Found
shunit2:ERROR testWhenDiskQuotaNotEnabled() returned non-zero return code.

Ran 1 test.

FAILED (failures=2)

My message is "Something". Why does shunit2 report "Something Found"?

Two reasons.

  1. When an assert fails, shUnit2 normally provides expected and actual output to make it easier to debug the test. Otherwise, the code author must put the values into the message, which is annoying and error prone.
  2. You've actually identified a bug in that the searched text is not included in the failure output. It is correctly output for calls to assertContains() though.

I just uploaded a new version of shUnit2 that fixes #2. Now when I run this script…

#!/bin/sh

testWhenDiskQuotaNotEnabled() {
  assertNotContains "Something" "Hello world" "world"
  assertContains "Something" "Hello world" "earth"
  return 0
}

. ${HOME}/var/wa/github.com/kward/shunit2/shunit2

I get this output.

$ ./i150.sh 
testWhenDiskQuotaNotEnabled
ASSERT:Something found:<world>
ASSERT:Something not found:<earth>

Ran 1 test.

FAILED (failures=2)
commented

Thanks for the timely fix. I confirm d0a57ff works on my side.

I would suggest to add some automated tests to this test framework.

Great to hear!

Automated tests already exist in shunit2_failures_test.sh. They previously tested that the term "found" came at the end of the line, but I fixed them to expect "found:" instead, which matches the other cases.