YAP 7.1.0
log2md.yap
Go to the documentation of this file.
1/**
2 * @file log2md.yap
3 * @author Vitor Santos Costa
4 *
5 *
6 */
7
8:- op(650,yfx, <-- ),
9 op(650,yfx, <-* ).
10
11:- module( log2md,
12 [open_log/1,
15 log_subsection/1,
16 log_paragraph/1,
18 (<--)/2,
19 (<-*)/2,
20 log_goal/1,
21 log_goal/1 as log_clause,
22 out/1,
23 out/2,
24 outln/1,
25 outln/2] ).
26
27:- use_module( library( maplist) ).
28
29
30*->/2/**
31 *
32 *
33 * @defgroup Log2MD Log Output of Tests in Markdown format.
34 *
35 * @ingroup Regression System Tests
36 *
37 * These primitives support writing a user-specified log of execution to an
38 * output file. The output file can be used for testing or debugging.
39 *
40 * Primitives include the ability to write a title, a Prolog clause or
41 * goal, and hooks for tracing calls. The log_goal/2 can be used to
42 * start a goal. Arguments of the form `<--/2` and `` can be used to
43 * track calls.
44 *
45 * The output format is markdown.
46 */
47
48open_log(F) :-
49 open( F, write, _Out, [alias(log)]).
50
51 /**
52 * @pred log_title( +String ) is det
53 *
54 * @param [in] S is a Prolog atom or string describing a title.
55 *
56 */
57 log_title( S ) :-
58 out( '## Report on ~a~n~n', [S]).
59
60 /**
61 * @pred log_section( +String ) is det
62 *
63 * @param [in] S is a Prolog atom or string describing a title.
64 *
65 */
66 log_section( S ) :-
67 out( '### Report on ~a~n~n', [S]).
68
69 /**
70 * @pred log_section( +String ) is det
71 *
72 * @param [in] S is a Prolog atom or string describing a title.
73 *
74 */
75 log_subsection( S ) :-
76 out( '#### Report on ~a~n~n', [S]).
77
78 /**
79 * @pred log_section( +String ) is det
80 *
81 * @param [in] S is a Prolog atom or string describing a title.
82 *
83 */
84 log_paragraph( S ) :-
85 out( '##### Report on ~a~n~n', [S]).
86
87 /**
88 * @pred log_unit( +String, + Level ) is det
89 *
90 * @param [in] _String_ is a Prolog atom or string describing a title
91 * @param [in] _Level_ is an integer number larager than 1 (do notice that )
92 *large numbers may be ignored ).
93 *
94 *
95 */
96 log_unit( S ) :-
97 out( '## Report on ~a~n~n', [S]).
98
99 /**
100 * @pred clause( +Term ) is det
101 *
102 * @param [in] Term is a Prolog clause or goal that it is going to
103 * be printed out using portray_clause/2.
104 *
105 */
106 log_goal( DecoratedClause ) :-
107 take_decorations(DecoratedClause, Clause),
108 out( '~~~~~~~~~n'),
109 portray_clause( user_error , Clause ),
110 portray_clause( log , Clause ),
111 out( '~~~~~~~~~n', []).
112
113 take_decorations( G, G ) :-
114 var(G),
115 var.
116 take_decorations(_ <-- G, NG ) :-
117 take_decorations,
118 take_decorations( G, NG ).
119 take_decorations(_ <-* G, NG ) :-
120 take_decorations,
121 take_decorations( G, NG ).
122 take_decorations(G, NG ) :-
123 G =.. [F|Args],
124 maplist( take_decorations, Args, NArgs ),
125 NG =.. [F|NArgs].
126
127 :- meta_predicate ( + <-- 0 ),
128 ( + <-* 0 ).
129
130 /**
131 * @pred log_goal( +Tag , :Goal )
132 *
133 * @param [in] evaluate goal _Goal_ with output before,
134 * during and after the goal has been evaluated.
135 *
136 */
137 A Goal :-
138 (
139 outln(A),
140 log_goal( Goal ),
141 call( Goal )
142 *->
143 out('succeded as~n'), log_goal(Goal)
144 ;
145 out( 'failed~n'),
146 out
147 ).
148
149 /**
150 * @pred +Tag <-- :Goal
151 *
152 * @param [in] output goal _Goal_ before and after being evaluated, but only
153 * taking the first solution. The _Tag_ must be an atom or a string.
154 *
155 */
156 Tag <-- Goal :-
157 (
158 outln(Tag),
159 log_goal( Goal ),
160 call( Goal )
161 ->
162 out('succeded as~n'),
163 log_goal(Goal),
164 log_goal
165 ;
166 out(failed)
167 ).
168
169
170 /**
171 * @pred out(+Format, +Args)
172 *
173 * @param [in] format the string given Args . The output is sent to
174 * user_error and to a stream with alias `log`;
175 *
176 */
177 out(Format, Args) :-
178 format( log, Format, Args),
179 format( user_error, Format, Args).
180
181 out(Format) :-
182 format( log, Format, []),
183 format( user_error, Format, []).
184
185 outln(Format, Args) :-
186 out(Format, Args), out('~n').
187 outln(Format) :-
188 out(Format), out('~n').
log_section( +String )
log_title( +String )
log_unit( +String, + Level )
op(+ P,+ T,+ A)
open(+ F,+ M,- S,+ Opts)
out(+Format, +Args)
portray_clause(+ S,+ C)
use_module( +Files )
call( 0:P )
var( T)
maplist( 2:Pred, + List1,+ List2)