Skip to content

Improving control of colorize #459

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

Merged
merged 6 commits into from
Apr 2, 2019

Conversation

lverns
Copy link
Contributor

@lverns lverns commented Mar 24, 2019

Fixes #458.

While the internal representation of the :colorize config key has changed from a string to a keyword, this should be fully backwards compatible with whatever users have in MIDJE_COLORIZE or .midje.clj.

Laverne Schrock added 3 commits March 23, 2019 14:40
Issue marick#458.

The test was passing before, but only because the `:times 0` was not being
honored by `preprequiste`. Now the test reflects reality, but we'll want to
modify implementation so that we change change `:times 1` back to `0` and still
have them pass.
The environment variable MIDJE_COLORIZE is now read once, and put into the
config. From there on out, it is treated just like any of the other
configuration flags.

Normalization of the :colorize config key was moved from the
midje.emission.colorize namespace to the midje.config namespace.

Previous order of precedence was (increasing order):
- Config file
- MIDJE_COLORIZE

Previous order of precedence was (increasing order):
- Config file
- MIDJE_COLORIZE
- Any programmatic changes to the config (e.g. via with-augmented-config)
Copy link
Collaborator

@philomates philomates left a comment

Choose a reason for hiding this comment

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

Thanks for contributing!
I checked out your patch and ran

export MIDJE_COLORIZE=false 
lein midje :autotest

which resulted in

======================================================================
Because failures in the initial load break autotest's dependency tracking,
autotest has been cancelled.
Wrong number of args (2) passed to: colorize/note

Do you also get this error?

(if (keyword? choice)
(name choice)
(str choice))))
(defmacro ^:private def-colorize
Copy link
Collaborator

Choose a reason for hiding this comment

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

I personally don't like using macros when functions also suffice.
In this case it could be something like

(defn- build-colorizer [normal-color reverse-color]
  (fn [a-str]
    (let [colorize-fn (case (config-choice :colorize)
                        :true normal-color
                        :reverse reverse-color
                        str)]
      (colorize-fn a-str))))

(def fail (build-colorizer color/red color/red-bg))
(def pass (build-colorizer color/green color/green-bg))
(def note (build-colorizer color/cyan color/cyan-bg))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll refactor this.

@lverns
Copy link
Contributor Author

lverns commented Mar 26, 2019

@philomates I haven't seen that arity error before, but I also haven't tried the autotest functionality.

I'll look into it.

Laverne Schrock added 3 commits March 30, 2019 09:15
Issue marick#458.

The colorizing functions should take any number of arguments (like str), but I
accidentally made them only accept one.
@lverns
Copy link
Contributor Author

lverns commented Mar 30, 2019

@philomates I was able to reproduce the issue and fix it. lein midje and lein midje :autotest now both work correctly with true, reverse, and false for MIDJE_COLORIZE.

Copy link
Collaborator

@philomates philomates left a comment

Choose a reason for hiding this comment

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

Nice, looks good 👍

@philomates philomates merged commit db248eb into marick:master Apr 2, 2019
@philomates
Copy link
Collaborator

I've released this under Midje 1.9.7 and updated the docs a little: https://github.com/marick/Midje/wiki/Configuration-files and https://github.com/marick/Midje/wiki/Colorizing

@lverns lverns deleted the improving-control-of-colorize branch April 2, 2019 14:43
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.

2 participants