Jldoctest: expecting (incorrectly) an empty output

I am getting the error below in a jldoctest. The command, when copy/pasted, works perfectly fine. What can be wrong here?

#```jldoctest
│ julia> using CellListMap
│ 
│ julia> box = Box([ 10  0  0 
│                     0 10  5
│                     0  0 10 ], 1)
│ Box{TriclinicCell, 3, Float64, 9}
│ unit cell matrix: [10.0 0.0 0.0; 0.0 10.0 5.0; 0.0 0.0 10.0]
│ cutoff: 1.0
│ number of computing cells on each dimension: [12, 17, 12]
│ computing cell sizes: [1.0, 1.0, 1.0] (lcell: 1)
│ Total number of cells: 2448
│ 
#│ ```
│ 
│ Subexpression:
│ 
│ box = Box([ 10  0  0 
│              0 10  5
│              0  0 10 ], 1)
│ 
│ Evaluated output:
│ 
│ 
│ 
│ Expected output:
│ 
│ Box{TriclinicCell, 3, Float64, 9}
│ unit cell matrix: [10.0 0.0 0.0; 0.0 10.0 5.0; 0.0 0.0 10.0]
│ cutoff: 1.0
│ number of computing cells on each dimension: [12, 17, 12]
│ computing cell sizes: [1.0, 1.0, 1.0] (lcell: 1)
│ Total number of cells: 2448

Very often the issue in such cases is that you forgot to properly pass around the io argument in your show method and instead print to stdout, not the specified IO object.

In this case it is this one:


function Base.show(io::IO,::MIME"text/plain",box::Box)
    println(typeof(box))
    println("  unit cell matrix: ", box.unit_cell.matrix) 
    println("  cutoff: ", box.cutoff)
    println("  number of computing cells on each dimension: ",box.nc)
    println("  computing cell sizes: ", box.cell_size, " (lcell: ",box.lcell,")")
    print("  Total number of cells: ", prod(box.nc))
end

Seems right, doesn’t it? At least that is what I understood from the help entry of show . (I am guessing that you’ll say that using print inside that is wrong :slight_smile: )

No, you always need to pass io as the first argument to print/println.

2 Likes