-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogfile.hsp
161 lines (151 loc) · 4.83 KB
/
logfile.hsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef logfile_hsp_included
#define logfile_hsp_included
#module
/*
ログファイル出力モジュールの初期化を行う
引数
hspver_str: HSP3ランタイムのバージョン
hsptest_version: hsptestのバージョン
testdir_path: テストを行うフォルダへのフルパス
*/
#deffunc init_logfile_module str hspver_str, str hsptest_version, str testdir_path
result_logfile_buf = "[RESULTS]\n"
detail_logfile_buf = "[FAILED TEST DETAILS]\n"
stdout_logfile_buf = "[CAPTURED STDOUT]\n"
hspver_str_ = hspver_str
hsptest_version_ = hsptest_version
testdir_path_ = testdir_path
passed_test_count = 0
failed_test_count = 0
ignored_test_count = 0
return
/*
ログ出力を行う際のセパレータヘッダ文字列を返す
引数
log_header: セパレータ内に表示する文字列
separator: セパレータに使用する文字
返り値
セパレータヘッダ文字列
*/
#defcfunc local get_log_header str log_header, str separator, local buf
buf = ""
repeat (100 - strlen(log_header)) / 2
buf += separator
loop
buf += log_header
repeat (100 - strlen(log_header)) / 2 + (100 - strlen(log_header)) \ 2
buf += separator
loop
return buf
/*
テスト結果をログバッファに追加する
引数
file_name: テストのファイル名
test_name: テスト名
status: テスト結果を示すコード
*/
#deffunc append_result_log str file_name, str test_name, int status
if status == 0 {
result_logfile_buf += file_name + "::" + test_name + ": PASSED\n"
passed_test_count++
} else : if status == 1 {
result_logfile_buf += file_name + "::" + test_name + ": FAILED\n"
failed_test_count++
} else : if status == 2 {
result_logfile_buf += file_name + "::" + test_name + ": IGNORED\n"
ignored_test_count++
}
return
/*
テストからキャプチャされた出力をログバッファに追加する
引数
file_name: テストのファイル名
test_name: テスト名
stdout: 標準出力文字列
*/
#deffunc append_stdout_log str file_name, str test_name, str stdout
stdout_logfile_buf += get_log_header(" " + file_name + "::" + test_name + " ", "=") + "\n"
stdout_logfile_buf += stdout
return
/*
失敗テストの詳細をログバッファに追加する
引数
file_name: テストのファイル名
test_name: テスト名
error_file: エラーが発生したファイル名
error_line: エラーが発生した行番号
error_detail: エラーメッセージ
callstack: コールスタック情報が格納された配列
*/
#deffunc append_detail_log str file_name, str test_name, str error_file, int error_line, str error_detail, array callstack
detail_logfile_buf += get_log_header(" " + file_name + "::" + test_name + " ", "=") + "\n"
if error_line == -1 {
detail_logfile_buf += "FAILED : " + error_detail + "\n"
return
}
detail_logfile_buf += "FAILED at file \"" + error_file + "\", line " + error_line + " : " + error_detail + "\n"
exist error_file
if strsize != -1 {
notesel file_buf
noteload error_file
repeat 6
get_line = error_line + cnt - 4
if get_line < 0 || get_line >= notemax : continue
noteget line_buf, get_line
if cnt == 3 {
detail_logfile_buf += strf("%5d", get_line + 1) + "|" + line_buf + " <--- ///// " + error_detail + " /////\n"
} else {
detail_logfile_buf += strf("%5d", get_line + 1) + "|" + line_buf + "\n"
}
loop
}
callstack_str = ""
callstack_exist = 0
repeat length(callstack)
if callstack(cnt + 1) == "" : break
split callstack(cnt), ";", f, l
exist f
if strsize != -1 {
notesel b
noteload f
noteget lb, int(l) - 1
lb = strtrim(lb, , ' ')
lb = strtrim(lb, , '\t')
callstack_str = " " + lb + "\n" + callstack_str
} else {
callstack_str = " ** File " + f + " not found **\n" + callstack_str
}
callstack_str = "File \"" + f + "\", line " + l + "\n" + callstack_str
callstack_exist = 1
loop
if callstack_exist {
detail_logfile_buf += get_log_header(" call stack ", "-") + "\n"
detail_logfile_buf += callstack_str
}
return
/*
ログファイルに書き込む文字列を取得する
返り値
ログファイルに書き込む文字列
*/
#defcfunc get_logfile_str local buf
buf = "ran on HSP " + hspver_str_ + ", hsptest " + hsptest_version_ + "\n\n"
buf += "test_dir: " + testdir_path_ + "\n\npassed: " + passed_test_count + "\nfailed: " + failed_test_count + "\n\n\n"
buf += result_logfile_buf + "\n\n"
buf += detail_logfile_buf
buf += get_log_header("", "=") + "\n\n\n"
buf += stdout_logfile_buf
buf += get_log_header("", "=")
return buf
/*
ログファイルを作成する
引数
logfile_path: ログファイルへのパス
*/
#deffunc make_logfile str logfile_path, local buf
buf = get_logfile_str()
notesel buf
notesave logfile_path
return
#global
#endif