sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 518 forks source link

Switched most occurrences of echo to printf, a bash builtin #195

Closed pgporada closed 7 years ago

pgporada commented 7 years ago

I ran the pgporada/bats/test/bats.bats 10 times and received the following average time

Average:
real 2.388 user 0.533 sys 0.203

Compared to sstephenson/bats/test/bats.bats 10 times

Average:
real 2.457 user 0.537 sys 0.203

It's marginally faster, but it does use more bash features.

All tests are passing

$ ./bats.bats
 ✓ no arguments prints usage instructions
 ✓ -v and --version print version number
 ✓ -h and --help print help
 ✓ invalid filename prints an error
 ✓ empty test file runs zero tests
 ✓ one passing test
 ✓ summary passing tests
 ✓ summary passing and skipping tests
 ✓ summary passing and failing tests
 ✓ summary passing, failing and skipping tests
 ✓ one failing test
 ✓ one failing and one passing test
 ✓ failing test with significant status
 ✓ failing helper function logs the test case's line number
 ✓ test environments are isolated
 ✓ setup is run once before each test
 ✓ teardown is run once after each test, even if it fails
 ✓ setup failure
 ✓ passing test with teardown failure
 ✓ failing test with teardown failure
 ✓ teardown failure with significant status
 ✓ failing test file outside of BATS_CWD
 ✓ load sources scripts relative to the current test file
 ✓ load aborts if the specified script does not exist
 ✓ load sources scripts by absolute path
 ✓ load aborts if the script, specified by an absolute path, does not exist
 ✓ output is discarded for passing tests and printed for failing tests
 ✓ -c prints the number of tests
 ✓ dash-e is not mangled on beginning of line
 ✓ dos line endings are stripped before testing
 ✓ test file without trailing newline
 ✓ skipped tests
 ✓ extended syntax
 ✓ pretty and tap formats
 ✓ pretty formatter bails on invalid tap
 ✓ single-line tests
 ✓ testing IFS not modified by run

37 tests, 0 failures

and

$ ./suite.bats 
 ✓ running a suite with no test files
 ✓ running a suite with one test file
 ✓ counting tests in a suite
 ✓ aggregated output of multiple tests in a suite
 ✓ a failing test in a suite results in an error exit code
 ✓ running an ad-hoc suite by specifying multiple test files
 ✓ extended syntax in suite

7 tests, 0 failures
mislav commented 7 years ago

Thanks for the suggestion, but echo is also a bash builtin, so I'm inclined to think that any performance benefit that you saw was accidental. Also, I don't think shaving 10ms of a single test run is worth this many changes to the codebase.

pgporada commented 7 years ago

Fair enough, it was still fun.

mislav commented 7 years ago

Sure, I'm thankful that you suggested a potential improvement in the first place! ✨