Skip to content

assert_successful_code, assert_unsuccessful_code, and assert_exit_code not behave as expected #559

@kuppo

Description

@kuppo
Q A
OS Linux
Shell & version bash 5.3.8
bashunit version 0.29.0

Summary

I have this issue drives me crazy. For three assertions, assert_successful_code, assert_unsuccessful_code, and assert_exit_code, the doc says I can use either command substitution $(command) or string command "command". But I always have trouble with the string command. I really don't know if the string command has been invoke or not. From it's side effect, I don't think it is invoke correctly.

Current behavior

I have no idea if the string command in those assertions is invoked correctly or not.

How to reproduce

Here is my test file.

#!/usr/bin/env bash
function test_touch_file_with_string_command() {
  assert_exit_code "0" "touch /tmp/tmp_file_with_string_command"
}

function test_touch_file_with_command_substitution() {
  assert_exit_code "0" "$(touch /tmp/tmp_file_with_command_substitution)"
}

function test_check_string_command_file() {
  assert_file_exists "/tmp/tmp_file_with_string_command"
}

function test_check_command_substitution_file() {
  assert_file_exists "/tmp/tmp_file_with_command_substitution"
}

Then I got this output. I also manually check /tmp directory, same result.

bashunit - 0.29.0 | Tests: 4
Running ./fake.sh
✓ Passed: Touch file with string command                                                                                                                                                                        19 ms
✓ Passed: Touch file with command substitution                                                                                                                                                                  24 ms
✗ Failed: Check string command file
    Expected '/tmp/tmp_file_with_string_command'
    to exist but 'do not exist'
✓ Passed: Check command substitution file                                                                                                                                                                       22 ms

There was 1 failure:

|1) ./fake.sh:10
|✗ Failed: Check string command file
|    Expected '/tmp/tmp_file_with_string_command'
|    to exist but 'do not exist'

Tests:      3 passed, 1 failed, 4 total
Assertions: 3 passed, 1 failed, 4 total

 Some tests failed 
Time taken: 262 ms

Expected behavior

I expect the touch command excuted so that tmp files exist in my /tmp.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdocumentationImprovements or additions to documentation

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions