-
Notifications
You must be signed in to change notification settings - Fork 517
Need to specify the full path to date command otherwise date returns empty string #228
Comments
What makes you think this is an issue with Bats? A much simpler test case passes:
It seems more likely this is either an issue with your system, or with these Bats extensions you're using. If the latter, you should file an issue with the offending extension(s). |
Did you check the output of date? As your test is written, there is no confirmation that the date command did anything expected. What I observed is that when specifying the full path, date returned a timestamp value per the formatting. But when called without the full path, it returned an empty string. My simpler scripts don't show that level of detail other than that the assert failed. But if you log the output to a file, I was able to see the issue. Again, this is running on a Mac. I did not try this on a version of Linux. |
I checked your example on Linux and it works there. Instead of:
I used:
Which, I think, you also intended to do. When you invoke those commands on Mac directly, without bats:
do they return the same output? |
I don't see that either, both variants produce output:
Can you provide a simpler test case that demonstrates your issue without any extensions? |
The following files demonstrate the issue:
~/work/Katas/bash/BashUnitTesting/test (master)$ cat test_helper.bash
load 'helpers/mocks/stub'
load 'helpers/bats-support/load'
load 'helpers/bats-assert/load'
:~/work/Katas/bash/BashUnitTesting/test (master)$ cat test1.bats
#!/usr/bin/env bats
source test_helper.bash
@test "test date command with full path on MAC OSX" {
export USE_FULL_PATH="TRUE"
run ./test1
assert_line --partial "17"
}
@test "test date command without using full path on MAC OSX" {
export USE_FULL_PATH="FALSE"
run ./test1
assert_line --partial "17"
}
~/work/Katas/bash/BashUnitTesting/test (master)$ cat test1
#!/bin/bash
if [ $USE_FULL_PATH = "TRUE" ]; then
echo
/bin/date '+%y%m%d-%H%M%S'
else
echo
date '+%y%m%d-%H%M%S'
fi
~/work/Katas/bash/BashUnitTesting/test (master)$ sudo bats test1.bats
✓ test date command with full path on MAC OSX
✓ test date command without using full path on MAC OSX
2 tests, 0 failures
~/work/Katas/bash/BashUnitTesting/test (master)$ bats test1.bats
✓ test date command with full path on MAC OSX
✗ test date command without using full path on MAC OSX
(from function
assert_line' in file helpers/bats-assert/src/assert.bash, line 491, in test file test1.bats, line 14)
assert_line --partial "17"' failed-- no output line contains substring --
substring : 17
output :
2 tests, 1 failure
The version of MAC OSX is Yosemite 10.10.5
The text was updated successfully, but these errors were encountered: