Skip to content

Source inexistent file makes test pass #611

@meleu

Description

@meleu
Q A
OS Linux
Shell & version bash 5.1.16(1)
bashunit version 0.34.0

<rant>
I feel like an idiot who, from time to time, let myself be seduced by bashunit's sexy documentation and advertised simplicity, then I try it and quickly become disappointed again. 😔

Then I open an issue, it's "solved", some months later I try it again just to realize that I can't (for now) trust bashunit as testing framework. 😭
</rant>

Summary

Sourcing a non-existent file makes a test suite to pass.

(also weird failure output)

How to reproduce

Today I got some freetime and decided "let me try bashunit again!".

Let me try to TDD a dead simple hello-world.

First step: red. Create a failing test:

#!/usr/bin/env bash

test_say_hello_world() {
  assert_same "Hello, World!" "$(hello)"
}

I run it and, as expected, it fails. Here sent as a screenshot just to show the weird output:

Image

Let's ignore the weird output and move on...

I want to test hello as a function that I'm going to add to a file named hello.sh, then before writing any production code, let's just source it in the test file:

#!/usr/bin/env bash

set_up() {
  source ./hello.sh
}

test_say_hello_world() {
  assert_same "Hello, World!" "$(hello)"
}

Now let's run the test:

$ bashunit hello_test.sh
bashunit - 0.34.0 | Tests: 1
Running hello_test.sh
✓ Passed: Say hello world                                                                     32ms

Tests:      1 passed, 1 total
Assertions: 0 passed, 0 total

 All tests passed
Time taken: 139ms

😱 - wtf?!

Let me add a 100% sure failing test:

#!/usr/bin/env bash

set_up() {
  source ./hello.sh
}

test_say_hello_world() {
  assert_same "Hello, World!" "$(hello)"
}

test_can_I_trust_bashunit?() {
  assert_same "true" "false"
}

And run it:

$ bashunit hello_test.sh
bashunit - 0.34.0 | Tests: 2
Running hello_test.sh
✓ Passed: Say hello world                                                                     18ms
✓ Passed: Can I trust bashunit?                                                               17ms

Tests:      2 passed, 2 total
Assertions: 0 passed, 0 total

 All tests passed
Time taken: 111ms

Now I've made a promise to myself: only try bashunit again in 2028.

Expected behavior

Sourcing a non-existent file to not make failing tests to pass.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions