Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added todo directive #38

Closed
wants to merge 195 commits into from
Closed

Added todo directive #38

wants to merge 195 commits into from

Conversation

andrewfowlie
Copy link

I have added the todo directive as described in the TAP specification - https://testanything.org/tap-version-13-specification.html

The syntax is similar to the skip directive:

@test "todo test that passes" {
  todo "this todo is done"
  return 0
}

@test "todo test that fails" {
  todo "this todo is outstanding"
  return 1
}

This results in

 ✓ todo test that passes (done: this todo is done)
 - todo test that fails (todo: this todo is outstanding)
   (in test file todo.tap, line 7)
     `todo "this todo is outstanding"' failed

2 tests, 0 failures, 1 todo, 1 done

and in TAP format:

1..2
ok 1 todo test that passes # done this todo is done
not ok 2 todo test that fails # todo this todo is outstanding
# (in test file todo.tap, line 7)
#   `todo "this todo is outstanding"' failed

dotmpe and others added 7 commits October 14, 2017 11:45
Moving the first test case in between the two duplicate test cases
caused a test failure, revealing the need to add `sort` in between
`grep` and `uniq -d`.
Extracted this function to encapsulate the operation prior to future
refactoring. It also fits better with the surrounding code style,
whereby small functions provide documentation, even for single-line
commands.
This achieves the same effect without launching a new process for the
`test` command. Also, using a multi-line `if` statement and keeping the
line length to under 80 columns helps with readability.
The `case` statement was a little difficult to read, and as it turns
out, using `$FIXTURE_ROOT/duplicate-tests.bats` enables us to make an
exact string comparison.

Also added some `printf` statements to see more clearly what the results
were when a test assertion fails.
The big thing I did in #8 was to eliminate as many
subshells, pipelines, and subprocesses as possible. Even though we
normally rely write scripts because of these features, in a framework
like Bats, they add up quickly and can have a big performance
impact—especially on Windows, especially when running virtualized.

Conseqently, replacing the previous `grep` pipeline with a `while` loop
causes the suite to run ~9% faster on macOS, and ~19% faster on Windows
(running under VMWare).

The following times were collected by running `time bin/bats test` on a:
  MacBook Pro
  Processor: 2.9 GHz Intel Core i5
  RAM: 8 GB 1867 MHz DDR3

Bash 4.4.12(1)-release running on macOS 10.12.6
-----------------------------------------------
Before this change:

  47 tests, 0 failures

  real    0m4.703s
  user    0m2.712s
  sys     0m1.570s

After this change:

  47 tests, 0 failures

  real    0m4.312s
  user    0m2.369s
  sys     0m1.166s

Git for Windows Bash 4.4.12(1)-release running on Windows 10 under
VMWare Fusion 8.5.8
------------------------------------------------------------------
Before this change:

  47 tests, 0 failures

  real    0m19.832s
  user    0m4.170s
  sys     0m8.893s

After this change:

  47 tests, 0 failures

  real    0m16.675s
  user    0m3.463s
  sys     0m7.297s
@andrewfowlie
Copy link
Author

If you like this I can also update docs + add some tests

@andrewfowlie
Copy link
Author

is it useful?

@sublimino
Copy link
Member

Hi @andrewfowlie, it looks useful!

bats is currently trying to get to a place where 1.0 can be shipped, I guess this would make sense after that release? Paging @btamayo @mbland @jasonkarns

@andrewfowlie
Copy link
Author

Cool. The changes are pretty small and it's useful for me because e.g., Jenkins can read TAP and knows about todos, and it'll let me write tests, then write my codes to pass the tests...

I don't know much about the development plan so have no strong opinions about whether it should be in 1.0 or later.

cdevinesr and others added 4 commits December 20, 2017 15:58
Addresses sstephenson/bats#240.  When outputting a 'pretty' formatted
output stream, the 'skip' message was being processed with a character
class of [^)].  I couldn't find a reason for this to be the case, so
I've swapped it out to check instead of printable characters, spaces
included ([:print:]).  Please advise if there is a problem with this
approach.

Tested using Bash 4.3.11(1)-release.
Two things here:

- judging by the "Added ..." lines of the changelog, this justifies pumping to 0.5.0 instead of a patch release, ie 0.4.1
- I changed the order of mentioning changes, I mention first the new stuff ("Added..."), then the improved stuff and then the bug fixes.
@@ -80,6 +80,11 @@ skip() {
exit 0
}

BATS_TEST_TODOED=''
todo() {
BATS_TEST_TODOED=${1:-1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ${1:-1} needs to be double-quoted.

Copy link
Contributor

@mbland mbland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments I've made here carry throughout the rest of the changes I didn't comment on. I realize some of the changes go along with the existing code style (i.e. using [ instead of [[), but go ahead and use the new style.

This'll probably be a 1.0 feature. You'll need to rebase/merge from master as needed. Whether you want to do that now or until it's about ready to merge is up to you.

We'll also need tests for this, of course.

@@ -270,14 +277,23 @@ bats_exit_trap() {
fi
fi

if [ -n "$BATS_TEST_TODOED" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use [[ and ]] for all new code, please.

if [ -n "$BATS_TEST_TODOED" ]; then
todoed=" # todo"
todone=" # done"
if [ "1" != "$BATS_TEST_TODOED" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[ and ]].

@@ -51,6 +53,22 @@ skip() {
advance
}

todo() {
local reason="$1"
[ -z "$reason" ] || reason=": $reason"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use [[ and ]], and expand this into an if statement to make it easier to scan.

@andrewfowlie
Copy link
Author

Thanks for the comments - will make the changes soonish

@andrewfowlie andrewfowlie requested a review from a team as a code owner June 4, 2018 01:17
cyphar and others added 10 commits February 11, 2019 02:01
It appears as though this test didn't actually test what it was supposed
to in 25505bd ("Skip pretty formatting if the first line isn't a
TAP plan"). It was supposed to test that bats-format-tap-stream would
not try to format non-TAP data -- but instead it just showed that the
preamble of test files was executed before printing the TAP header
(something that is not going to be the case with the suite refactor).

Fixes: 25505bd ("Skip pretty formatting if the first line isn't a TAP plan")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This allows us to remove most of the complicated handling between
bats-exec-test and bats-exec-suite (which had a complicated interplay
due to the fact they both supported multi-test execution).

Instead, multi-test execution is entirely left to bats-exec-suite and
bats-exec-test only handles a single test. This entirely removes the
need for the magic output handling in bats-exec-test -- and opens the
door to suite-wide parallelism in one fell swoop.

The only downside is that bats-preprocess is run multiple times on the
same source file, but a follow-up patch will improve the caching of
pre-processed files such that they will only be processed once.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Most well-behaved bats tests (where they aren't writing to shared data
between test executions) are able to be executed in parallel, but to
date bats has always executed them in serial. This is incredibly
wasteful for trivially parallelisable tests, and can result in fairly
inflated test times for no good reason. Parallel exeuction is done
suite-wide, so it makes no difference how the tests are structured.

Unfortunately, because some suites might be implicitly serial (like
bats' own test suite) we cannot make the default mode execute in
parallel. In addition, there is currently no way of tagging that a
*specific* test has to be run in serial (so that the rest can be run in
parallel) -- but that can be done in future work.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Testing that parallel execution actually works is a bit difficult, so
the most trivial way of doing it is to just have a bunch of sleep tests
and make sure that they run faster than would be possible if they were
run in serial.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Added instructions for installing on Git Bash
Tweaked some wording after #143
bats: support parallel execution of tests
@Aazhar
Copy link

Aazhar commented Jun 12, 2019

Hello,
I would like to know if this feature will merged anytime soon ?
Thanks

@sublimino
Copy link
Member

@andrewfowlie (due to the passing of time, sorry!) this branch has some conflicts, could you rebase master onto it and ensure the tests still pass?

In general LGTM, although I'd like a second opinion and to test this in anger for a while. If you'd like to test the latest (e.g. rebased) version of this @Aazhar please do so and let us know here : ]

@Aazhar
Copy link

Aazhar commented Jun 16, 2019

ok so after reviewing this PR, I'm questioning the meaning of 'done' todos in the initial post.
Actually imho, all todos should be counted as todos, regardless of their supposed result.

@andrewfowlie
Copy link
Author

andrewfowlie commented Jun 16, 2019 via email

@andrewfowlie
Copy link
Author

arggh, something has gone wrong with my PR/rebase against master. There was some small complication because some of my modified files had been removed from the upstream repo, so I did some things manually. But I thought it worked (master...andrewfowlie:master), but this PR seems to include all kinds of commits and changes.

Maybe it's this problem - https://stackoverflow.com/questions/18323665/pull-request-on-github-showing-commits-rebased-from-master

@jasonkarns
Copy link
Member

I'm assuming part of the problem here is that the changes were made on the master branch instead of on a feature branch.

@jasonkarns
Copy link
Member

As to "done" todos...

@Aazhar the TAP spec itself indicates that tests marked as TODO that pass should be counted as "bonus" tests.

Personally I disagree with the TAP spec here. I believe rspec's behavior is better here. A test that's marked as TODO should not pass. If it does, the test is either not a valid test (it's testing the wrong thing) and needs to be updated; or the test is valid and the functionality is complete, in which case, the test needs to be updated (remove the TODO marker). Ergo, in both scenarios, the test needs "fixed". Rspec reports pending tests that pass as failures, and I believe that is the proper behavior. However, since the TAP spec is explicit, and at least TAP reports them separate from regular passing tests, I'll concede that spec-compliant behavior is acceptable.

However, as a test suite that contains DONE TODOs requires changes, I think we should follow rspec's lead here and return a non-zero exit for the suite in such a case.

@andrewfowlie
Copy link
Author

That makes sense. I am very busy travelling right now. I’m happy for anyone to finish this PR/if anyone knows how to fix the aforementioned GitHub problem with the PR please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet