@@ -76,6 +76,11 @@ function memory_usage(rec::TestRecord)
7676 return rec. rss
7777end
7878
79+
80+ #
81+ # overridable I/O context for pretty-printing
82+ #
83+
7984struct TestIOContext
8085 io:: IO
8186 lock:: ReentrantLock
@@ -100,23 +105,77 @@ function test_IOContext(::Type{TestRecord}, io::IO, lock::ReentrantLock, name_al
100105 )
101106end
102107
103- # Message types for the printer channel
104- # (:started, test_name, worker_id)
105- # (:finished, test_name, worker_id, record)
106- # (:errored, test_name, worker_id)
107- const printer_channel = Channel {Tuple} (100 )
108-
109108function print_header (:: Type{TestRecord} , ctx:: TestIOContext , testgroupheader, workerheader)
110- printstyled (ctx. io, " " ^ (ctx. name_align + textwidth (testgroupheader) - 3 ), " | " )
111- printstyled (ctx. io, " | ---------------- CPU ---------------- |\n " , color = :white )
112- printstyled (ctx. io, testgroupheader, color = :white )
113- printstyled (ctx. io, lpad (workerheader, ctx. name_align - textwidth (testgroupheader) + 1 ), " | " , color = :white )
114- printstyled (ctx. io, " Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB) |\n " , color = :white )
115- return nothing
109+ lock (ctx. lock)
110+ try
111+ printstyled (ctx. io, " " ^ (ctx. name_align + textwidth (testgroupheader) - 3 ), " | " )
112+ printstyled (ctx. io, " | ---------------- CPU ---------------- |\n " , color = :white )
113+ printstyled (ctx. io, testgroupheader, color = :white )
114+ printstyled (ctx. io, lpad (workerheader, ctx. name_align - textwidth (testgroupheader) + 1 ), " | " , color = :white )
115+ printstyled (ctx. io, " Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB) |\n " , color = :white )
116+ flush (ctx. io)
117+ finally
118+ unlock (ctx. lock)
119+ end
120+ end
121+
122+ function print_test_started (:: Type{TestRecord} , wrkr, test, ctx:: TestIOContext )
123+ lock (ctx. lock)
124+ try
125+ printstyled (test, color = :white )
126+ printstyled (
127+ lpad (" ($wrkr )" , ctx. name_align - textwidth (test) + 1 , " " ), " |" ,
128+ " " ^ ctx. elapsed_align, " started at $(now ()) \n " , color = :white
129+ )
130+ flush (ctx. io)
131+ finally
132+ unlock (ctx. lock)
133+ end
134+ end
135+
136+ function print_test_finished (test, wrkr, record:: TestRecord , ctx:: TestIOContext )
137+ lock (ctx. lock)
138+ try
139+ printstyled (ctx. io, test, color = :white )
140+ printstyled (ctx. io, lpad (" ($wrkr )" , ctx. name_align - textwidth (test) + 1 , " " ), " | " , color = :white )
141+ time_str = @sprintf (" %7.2f" , record. time)
142+ printstyled (ctx. io, lpad (time_str, ctx. elapsed_align, " " ), " | " , color = :white )
143+
144+ gc_str = @sprintf (" %5.2f" , record. gctime)
145+ printstyled (ctx. io, lpad (gc_str, ctx. gc_align, " " ), " | " , color = :white )
146+ percent_str = @sprintf (" %4.1f" , 100 * record. gctime / record. time)
147+ printstyled (ctx. io, lpad (percent_str, ctx. percent_align, " " ), " | " , color = :white )
148+ alloc_str = @sprintf (" %5.2f" , record. bytes / 2 ^ 20 )
149+ printstyled (ctx. io, lpad (alloc_str, ctx. alloc_align, " " ), " | " , color = :white )
150+
151+ rss_str = @sprintf (" %5.2f" , record. rss / 2 ^ 20 )
152+ printstyled (ctx. io, lpad (rss_str, ctx. rss_align, " " ), " |\n " , color = :white )
153+
154+ flush (ctx. io)
155+ finally
156+ unlock (ctx. lock)
157+ end
158+ end
159+
160+ function print_test_errorred (:: Type{TestRecord} , wrkr, test, ctx:: TestIOContext )
161+ lock (ctx. lock)
162+ try
163+ printstyled (test, color = :red )
164+ printstyled (
165+ lpad (" ($wrkr )" , ctx. name_align - textwidth (test) + 1 , " " ), " |" ,
166+ " " ^ ctx. elapsed_align, " failed at $(now ()) \n " , color = :red
167+ )
168+
169+ flush (ctx. io)
170+ finally
171+ unlock (ctx. lock)
172+ end
116173end
117174
118175
119- # # entry point
176+ #
177+ # entry point
178+ #
120179
121180function runtest (:: Type{TestRecord} , f, name, init_code)
122181 function inner ()
@@ -524,6 +583,12 @@ function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
524583 status_lines_visible[] = 3
525584 end
526585
586+ # Message types for the printer channel
587+ # (:started, test_name, worker_id)
588+ # (:finished, test_name, worker_id, record)
589+ # (:errored, test_name, worker_id)
590+ printer_channel = Channel {Tuple} (100 )
591+
527592 push! (tasks, @async begin
528593 last_status_update = Ref (time ())
529594 try
@@ -542,47 +607,21 @@ function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
542607
543608 # Optionally print verbose started message
544609 if do_verbose
545- printstyled (test_name, color = :white )
546- printstyled (
547- lpad (" ($wrkr )" , name_align - textwidth (test_name) + 1 , " " ), " |" ,
548- " " ^ elapsed_align, " started at $(now ()) \n " , color = :white
549- )
550- flush (stdout )
610+ clear_status ()
611+ print_test_started (RecordType, wrkr, test_name, io_ctx)
551612 end
552613
553614 elseif msg_type == :finished
554615 test_name, wrkr, record = msg[2 ], msg[3 ], msg[4 ]
555616
556- # Clear status lines before printing result
557617 clear_status ()
558-
559- # Print test result
560- printstyled (test_name, color = :white )
561- printstyled (stdout , lpad (" ($wrkr )" , name_align - textwidth (test_name) + 1 , " " ), " | " , color = :white )
562- time_str = @sprintf (" %7.2f" , record. time)
563- printstyled (stdout , lpad (time_str, elapsed_align, " " ), " | " , color = :white )
564- gc_str = @sprintf (" %5.2f" , record. gctime)
565- printstyled (stdout , lpad (gc_str, io_ctx. gc_align, " " ), " | " , color = :white )
566- percent_str = @sprintf (" %4.1f" , 100 * record. gctime / record. time)
567- printstyled (stdout , lpad (percent_str, io_ctx. percent_align, " " ), " | " , color = :white )
568- alloc_str = @sprintf (" %5.2f" , record. bytes / 2 ^ 20 )
569- printstyled (stdout , lpad (alloc_str, io_ctx. alloc_align, " " ), " | " , color = :white )
570- rss_str = @sprintf (" %5.2f" , record. rss / 2 ^ 20 )
571- printstyled (stdout , lpad (rss_str, io_ctx. rss_align, " " ), " |\n " , color = :white )
572- flush (stdout )
618+ print_test_finished (test_name, wrkr, record, io_ctx)
573619
574620 elseif msg_type == :errored
575621 test_name, wrkr = msg[2 ], msg[3 ]
576622
577- # Clear status lines before printing error
578623 clear_status ()
579-
580- printstyled (test_name, color = :red )
581- printstyled (
582- lpad (" ($wrkr )" , name_align - textwidth (test_name) + 1 , " " ), " |" ,
583- " " ^ elapsed_align, " failed at $(now ()) \n " , color = :red
584- )
585- flush (stdout )
624+ print_test_errorred (RecordType, wrkr, test_name, io_ctx)
586625 end
587626 end
588627
0 commit comments