Clojure

Add a way to access the current test var in :each fixtures for clojure.test

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code
  • Approval:
    Triaged

Description

When looking at (log) output from tests written with clojure.test, I would like to be able to identify the output associated with each test. A mechanism to expose the current test var within an :each fixture would enable this.

One mechanism might be to bind a test-var var with the current test var before calling the each-fixture-fn in clojure.test/test-all-vars.

Proposed: The proposed patch (clj840-20161122.diff) allows 'each' fixtures to access the var associated with the currently executing test by using (first *testing-vars*). As a result of this change, 'each' fixtures are able to access the metadata associated with the current test var, including the name.

The patch achieves the above by changing the order in which functions are wrapped when a test and its associated 'each' fixtures are run. Before this patch, 'each' fixtures were combined into a single higher-order function, which was then given a thunk containing an invocation of the test-var function to execute as its body. After this patch, the test-var function is now responsible for joining and executing 'each' fixtures but, importantly, it does so within the scope of the binding expression that adds the current test var to *testing-vars*. test-var now invokes the joined fixtures function, rather than the joined fixtures function being given a thunk that invokes test-var.

Patch: clj840-20161122.diff

  1. add-test-var.diff
    21/Oct/11 10:34 PM
    3 kB
    Hugo Duncan
  2. clj840-2.diff
    25/Oct/11 6:26 PM
    2 kB
    Stuart Sierra
  3. clj840-20161122.diff
    22/Nov/16 11:30 AM
    2 kB
    Joe Littlejohn

Activity

Hugo Duncan made changes -
Field Original Value New Value
Attachment add-test-var.diff [ 10495 ]
Stuart Sierra made changes -
Attachment clj840-2.diff [ 10497 ]
Stuart Sierra made changes -
Assignee Stuart Sierra [ stuart.sierra ]
Stuart Sierra made changes -
Assignee Stuart Sierra [ stuart.sierra ]
Andy Fingerhut made changes -
Patch Code [ 10001 ]
Joe Littlejohn made changes -
Attachment clj840-20161122.diff [ 16294 ]
Alex Miller made changes -
Approval Triaged [ 10120 ]
Description When looking at (log) output from tests written with clojure.test, I would like to be able to identify the output associated with each test. A mechanism to expose the current test var within an :each fixture would enable this.

One mechanism might be to bind a *test-var* var with the current test var before calling the each-fixture-fn in clojure.test/test-all-vars.
When looking at (log) output from tests written with clojure.test, I would like to be able to identify the output associated with each test. A mechanism to expose the current test var within an :each fixture would enable this.

One mechanism might be to bind a *test-var* var with the current test var before calling the each-fixture-fn in clojure.test/test-all-vars.

*Patch:* clj840-20161122.diff
Alex Miller made changes -
Labels clojure.test
Alex Miller made changes -
Description When looking at (log) output from tests written with clojure.test, I would like to be able to identify the output associated with each test. A mechanism to expose the current test var within an :each fixture would enable this.

One mechanism might be to bind a *test-var* var with the current test var before calling the each-fixture-fn in clojure.test/test-all-vars.

*Patch:* clj840-20161122.diff
When looking at (log) output from tests written with clojure.test, I would like to be able to identify the output associated with each test. A mechanism to expose the current test var within an :each fixture would enable this.

One mechanism might be to bind a *test-var* var with the current test var before calling the each-fixture-fn in clojure.test/test-all-vars.

*Proposed:* The proposed patch (clj840-20161122.diff) allows 'each' fixtures to access the var associated with the currently executing test by using {{(first \*testing-vars\*)}}. As a result of this change, 'each' fixtures are able to access the metadata associated with the current test var, including the name.

The patch achieves the above by changing the order in which functions are wrapped when a test and its associated 'each' fixtures are run. Before this patch, 'each' fixtures were combined into a single higher-order function, which was then given a thunk containing an invocation of the {{test-var}} function to execute as its body. After this patch, the {{test-var}} function is now responsible for joining and executing 'each' fixtures but, importantly, it does so *within the scope of the binding expression* that adds the current test var to {{\*testing-vars\*}}. {{test-var}} now invokes the joined fixtures function, rather than the joined fixtures function being given a thunk that invokes {{test-var}}.

*Patch:* clj840-20161122.diff

People

Vote (1)
Watch (4)

Dates

  • Created:
    Updated: