# Normalizing colored output for comparison?

**URL:** <https://discourse.julialang.org/t/normalizing-colored-output-for-comparison/6486>\
**Category:** General Usage\
**Created:** [October 16, 2017, 8:27pm UTC](https://discourse.julialang.org/t/normalizing-colored-output-for-comparison/6486 "2017-10-16T20:27:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [October 16, 2017, 8:27pm UTC](https://discourse.julialang.org/t/normalizing-colored-output-for-comparison/6486/1 "2017-10-16T20:27:24Z")

</div>

Are there any good options for checking colored output in your tests that work across julia versions?

I keep coming across this issue where I want to validate that some colored output shows up correctly, but the issue is that the exact escape codes used change between Julia versions, so I end up having ugly switches in my test code with differently-escaped versions of the same text.

I’ve thought about writing about something to normalize strings to some kind of canonical representation that can be compared, but I wanted to check to see if there’s a solution already out there.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 17, 2017, 4:46am UTC](https://discourse.julialang.org/t/normalizing-colored-output-for-comparison/6486/2 "2017-10-17T04:46:18Z")

</div>

You can use [https://github.com/KristofferC/Crayons.jl](https://github.com/KristofferC/Crayons.jl)

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [October 18, 2017, 1:30am UTC](https://discourse.julialang.org/t/normalizing-colored-output-for-comparison/6486/3 "2017-10-18T01:30:56Z")

</div>

I looked at Crayons.jl a little but it wasn’t clear how it would help my testing case.

As a more concrete example, my DeepDiffs.jl package displays diffs of a variety of datatypes, and can pretty-print them with red/green highlighting:

![deepdiffs](https://global.discourse-cdn.com/julialang/original/3X/4/d/4da83d3141e1c07d0f384c2e36fe37fdd7f628b5.png)

Testing the printing functionality is pretty gnarly and each test case needs multiple expected output samples depending on the Julia version. What I really want is a way to test that the output appears a certain way to the user, without being sensitive to exactly the sequence of escape characters used to do the coloring.

I suppose if I used Crayons.jl to do the coloring than the output wouldn’t change with Julia versions, but then it might change with Crayons versions.

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [October 18, 2017, 1:32am UTC](https://discourse.julialang.org/t/normalizing-colored-output-for-comparison/6486/4 "2017-10-18T01:32:05Z")

</div>

additionally - it would be great if _I_ could refactor how I do the printing (which might change the escaping) without needing to regenerate my example output.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 18, 2017, 9:15am UTC](https://discourse.julialang.org/t/normalizing-colored-output-for-comparison/6486/5 "2017-10-18T09:15:06Z")

</div>

> [@ssfrr](#):
>
> I suppose if I used Crayons.jl to do the coloring than the output wouldn’t change with Julia versions, but then it might change with Crayons versions.

That’s what I meant. Output changing from Crayons would be a bug.

Parsing the text into ANSI codes and normalizing sounds like an awful amount of work.

---

<div class="post-metadata">

**Author:** ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)\
**Post date:** [October 18, 2017, 3:54pm UTC](https://discourse.julialang.org/t/normalizing-colored-output-for-comparison/6486/6 "2017-10-18T15:54:51Z")

</div>

While not exactly addressing your question, I am very familiar with the kind of testing struggle you describe here. maybe a different approach to lighten the burden of testing colored output is using [GitHub - JuliaTesting/ReferenceTests.jl: Utility package for comparing data against reference files](https://github.com/Evizero/ReferenceTests.jl) . It supports color and it allows for simple management and updating of the references
