-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_testcall_script.hsp
207 lines (182 loc) · 6.76 KB
/
make_testcall_script.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef make_testcall_script_hsp_included
#define make_testcall_script_hsp_included
#include "append_data.hsp"
#module
/*
一時ディレクトリ内の構成を守るためのフォルダを一時ディレクトリ内に追加で作成する
例えば、#include "path/to/module.as"と記述されていた場合、"path/to"フォルダを作成する
引数
path: フォルダを含むファイルへのパス
*/
#deffunc local make_folder_in_path str path, local parent, local buf, local buf_size
parent = getpath(path, 32)
strrep parent, "/", "\\"
parent = strtrim(parent, 2, '\\')
if parent == "" : return
make_folder_in_path parent
dirlist2h@ 1
dirlist2@ buf_size, "*", 1 | 2, '\\'
sdim buf, buf_size + 1
dirlist2r@ buf
if instr(buf, 0, temp_test_env_dir + "\\" + parent) == -1 {
mkdir temp_test_env_dir + "\\" + parent
}
return
#deffunc local fetch_included_files_recursive str hsp_source_file_path, array included_source_list, var included_source_list_index, local escaped_cwd, local file_content_buf, local file_line_count, local file_line, local include_file, local include_file_abs
// ソースファイルをロード
notesel file_content_buf
noteload hsp_source_file_path
file_line_count = notemax
// ソースファイルの中を1行ずつ見る
repeat file_line_count
// #include文であったときは、そのファイルの存在を確かめてフルパスでinclude_fileに取得
noteget file_line, cnt
include_file = submatch(file_line, "#include\\s*\"([^\"]+)\"")
if include_file == "" : continue
strrep include_file, "/", "\\" // パス表現は\をデリミタとして統一する
sdim include_file_abs, 260
offset = 0
sdim full_path
if is_relative_path(include_file) {
GetFullPathNameA include_file, 260, varptr(include_file_abs), offset
} else {
include_file_abs = include_file
}
exist include_file_abs
if strsize == -1 : continue
// 既にリストに含まれているファイル内は中身のincludeを検索しない
found = 0
repeat included_source_list_index
if include_file_abs == included_source_list(cnt) {
found = 1
break
}
loop
if found : continue
// リストの末尾に見つかったインクルードファイルを追加
included_source_list(included_source_list_index) = include_file_abs
included_source_list_index++
// インクルードファイル内のインクルードファイルを検索
fetch_included_files_recursive include_file_abs, included_source_list, included_source_list_index
loop
; chdir escaped_cwd
noteunsel
return
#deffunc local copy_file_used_in_test local file_num, local script_path_list, local index_buf
// インクルードファイルパス一覧用のバッファを準備
sdim script_path_list, 260, 512
index_buf = 0
// カレントディレクトリ内のファイルパス一覧を取得
dirlist2h@ 1
dirlist2@ path_buf_size, "*", 1, '\\'
sdim path_buf, path_buf_size + 1
dirlist2r@ path_buf
// パス一覧を1行ずつ見る
notesel path_buf
file_num = notemax
repeat file_num
notesel path_buf
noteget path, cnt
// パスにファイルが存在しないときは無視
exist path
if strsize == -1 : continue
// テスト用一時ディレクトリ内のファイルなら無視
if instr(path, 0, temp_test_env_dir) != -1 : continue
// ファイルがhspスクリプトであるとき、スクリプト一覧に加える
if getpath(path, 2) == ".hsp" || getpath(path, 2) == ".as" {
if is_relative_path(path) {
sdim full_path, 260
offset = 0
GetFullPathNameA path, 260, varptr(full_path), offset
script_path_list(index_buf) = full_path
} else {
script_path_list(index_buf) = path
}
index_buf++
fetch_included_files_recursive path, script_path_list, index_buf
}
loop
// 集まったインクルードファイルのフォルダ構成を一時ディレクトリ以下にコピーする
repeat index_buf
path = script_path_list(cnt)
dest_path = temp_test_env_dir + "\\" + none_drive_letter(path)
if getpath(path, 32) != "" {
make_folder_in_path none_drive_letter(path)
}
copy_with_edit path, dest_path
loop
return
/*
テストスクリプトを生成する
引数
testfile_name: スクリプト内でincludeされるテストスクリプト名
testlabel_name: スクリプト内でincludeされるテストサブルーチンラベル名
runtime_name: スクリプトを実行するランタイム名
返り値
テストスクリプトが保存されたファイルへのパス
*/
#defcfunc make_temp_test str testfile_name, str testlabel_name, str runtime_name
// 一時ディレクトリを作成
temp_test_env_dir = "__tmpenv"
mkdir temp_test_env_dir
cur_dir_in_temp_dir = dir_cur + "\\" + temp_test_env_dir + "\\" + none_drive_letter(dir_cur)
// カレントディレクトリ以下のスクリプトを一時ディレクトリにコピー
copy_file_used_in_test
// 呼び出し用のスクリプトを作成
temp_test_name = "__testtmp.hsp"
generated_code_buf = "#runtime \"" + runtime_name + "\"\n"
generated_code_buf += "#include \"kernel32.as\"\n"
generated_code_buf += "AllocConsole\n"
generated_code_buf += "goto *__start\n"
generated_code_buf += "#include \"hsptest_common.as\"\n"
generated_code_buf += "#include \"" + testfile_name + "\"\n"
generated_code_buf += "*__start\n"
generated_code_buf += "gosub *__testinit\n"
generated_code_buf += "gosub " + testlabel_name + "\n"
generated_code_buf += "__result_str = get_pass_result_format() + \"\\n\"\n"
generated_code_buf += "WriteFile __stdout_handle, __result_str, strlen(__result_str), 0, 0\n"
generated_code_buf += "end 0"
notesel generated_code_buf
generated_code_path = cur_dir_in_temp_dir + "\\" + temp_test_name
notesave generated_code_path
; copy_with_edit temp_test_name, temp_test_env_dir + "\\" + temp_test_name
; delete temp_test_name
return generated_code_path
/*
渡したフォルダの中身を全て削除する
引数
path_to_dir: 中身を空にしたいフォルダへのパス
*/
#deffunc local delete_all_file str path_to_dir, local now_cwd, local dirs, local dir_num, local files, local file_num, local name
// 指定したフォルダ内に移動
now_cwd = dir_cur
chdir path_to_dir
// フォルダをまず削除
dirlist dirs, "*", 5
dir_num = stat
repeat dir_num
notesel dirs
noteget name, cnt
delete_all_file name
RemoveDirectory name
loop
// ファイルを削除
dirlist files, "*", 1
file_num = stat
repeat file_num
notesel files
noteget name, cnt
delete name
loop
// 元のフォルダに帰る
chdir now_cwd
return
/*
テストスクリプトおよびaxファイルを削除する
*/
#deffunc delete_temp_test
delete_all_file temp_test_env_dir
RemoveDirectory temp_test_env_dir
return
#global
#endif