Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ name: CI
on:
- push
- pull_request

# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read

env:
JULIA_NUM_THREADS: 1
JULIA_NUM_THREADS: 2
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand All @@ -12,8 +18,7 @@ jobs:
fail-fast: true
matrix:
version:
- '1.9'
#- 'lts'
- 'lts'
- 'pre'
os:
- ubuntu-latest
Expand All @@ -24,16 +29,7 @@ jobs:
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@v1
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ version = "1.2.2-DEV"

[compat]
Aqua = "0.8.9"
julia = "1.9.0"
Test = "1.9.0"
julia = "1.10.0"
Test = "1.10.0"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Expand Down
12 changes: 10 additions & 2 deletions src/ShowMethodTesting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ function parse_show(x::String;
for (k, v) in repl
s = replace(s, k => v)
end
# add spaces between digits and other characters (except dots), to interpret them as numbers
s = replace(s, r"(?<=\d)(?=[^\d.])|(?<=[^\d.])(?=\d)" => s" ")
#
# add spaces between digits and other characters (except dots and scientific notation),
# to interpret them as numbers
#
NUMBER_PATTERN = r"([+-]?\d*\.?\d+[eEfFrR][+-]?\d+|[+-]?\d*\.?\d+)"
# Replaces the matched number N with " N " (a space on each side).
# Then, it cleans up multiple consecutive spaces.
s = replace(s, NUMBER_PATTERN => s" \0 ")
# Clean up any leftover multiple spaces and surrounding whitespace.
s = replace(strip(s), r"\s+" => " ")
if vector_simplify # keep only first and last array elements
s = replace(s, r"(\[)([^,\]]+)(,.*,)([^,\]]+)(\])" => s"\1\2 \4\5")
end
Expand Down
43 changes: 32 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,41 @@ end
x::Int
path::String
vec::Vector{Float64}
a::Float32
b::Float32
c::Float64
d::Float64
end
Base.show(io::IO, ::MIME"text/plain", a::A) = print(io, "Object with Int($(a.x)), $(a.path) and $(a.vec)")
a = A(1, "/usr/bin/bash", [1.0, π, 7.5, √2])
@test parse_show(a) ≈ "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]"
@test "Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]" ≈ parse_show(a)
@test parse_show("Object with Int(1), /usr/bin/bash and [1.0, 3.1415, 7.5, 1.4142]") ≈ parse_show(a)
@test_throws AssertionError parse_show(a) ≈ "Object with Int(2), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951]"
@test !isapprox(parse_show(a), "Object with Int(2), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951]"; assertion_error=false)
Base.show(io::IO, ::MIME"text/plain", a::A) =
print(io, """
Object with Int($(a.x)), $(a.path) and $(a.vec) vector.
a, b, c, d = $(a.a), $(a.b), $(a.c), $(a.d)
""")
a = A(1, "/usr/bin/bash", [1.0, π, 7.5, √2], 1.3f-17, 2.6f17, 1.3e-17, 2.6f17)
@test parse_show(a) ≈ """
Object with Int(1), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951] vector.
a, b, c, d = 1.3e-17, 2.6e17, 1.3e-17, 2.6000000279170253e17
"""
@test """
Object with Int(1), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951] vector.
a, b, c, d = 1.3e-17, 2.6e17, 1.3e-17, 2.6000000279170253e17
""" ≈ parse_show(a)
@test parse_show("""
Object with Int(1), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951] vector.
a, b, c, d = 1.3e-17, 2.6e17, 1.3e-17, 2.6000000279170253e17
""") ≈ parse_show(a)
@test_throws "comparison failed" parse_show(a) ≈ "Object with Int(2), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951]"
# do not throw error with assertion_error == false
@test !isapprox(parse_show(a), """
Object with Int(2), /usr/bin/bash and [1.0, 3.141592653589793, 7.5, 1.4142135623730951]"
"""; assertion_error=false)
# Test show method
@test contains(repr("text/plain", parse_show(a)), "Object with Int( 1 )")
@test parse_show([a, a, a, a]; repl=["/usr/bin/bash" => "", r"^((?:[^\n]*\n){3}).*"s => s"\1"]) ≈ """
4 -element Vector{A}:
Object with Int( 1 ), and [ 1.0 1.4142135623730951 ]
Object with Int( 1 ), and [ 1.0 1.4142135623730951 ]
# Test custom multiple substitions (keep only first 3 lines)
@test parse_show([a, a, a, a]; repl=["/usr/bin/bash" => "", r"^((?:[^\n]*\n){3}).*"s => s"\1"], vector_simplify=false) ≈ """
4-element Vector{A}:
A(1, "/usr/bin/bash", [1.0, 3.141592653589793, 7.5, 1.4142135623730951], 1.3f-17, 2.6f17, 1.3e-17, 2.6000000279170253e17)
A(1, "/usr/bin/bash", [1.0, 3.141592653589793, 7.5, 1.4142135623730951], 1.3f-17, 2.6f17, 1.3e-17, 2.6000000279170253e17)
"""
@test_throws ArgumentError parse_show([a, a, a, a]; repl=["a", "b"])
# compact printing
Expand Down