統合テストに、最新版Autotest.mkを反映
[YACASL2.git] / test / system / casl2 / Define_test.mk
1 ######################################################################
2 # マクロ
3 ######################################################################
4
5 # 引数のファイルをチェックし、内容がない場合は削除
6 # 用例: $(call rm_null,file)
7 define rm_null
8     if test ! -s $1; then $(RM) $1; fi
9 endef
10
11 # 説明ファイルの内容を、引数のファイルに出力
12 # 用例: $(call desc_log,file_out)
13 define desc_log
14     if test -s $(DESC_FILE); then $(CAT) $(DESC_FILE) >>$1; fi
15 endef
16
17 # テスト実行の経過時間を、ファイルに出力して表示
18 # 引数は、テスト名、コマンドファイル、出力ファイル
19 # 用例: $(call time_cmd,name,file_cmd,file_out)
20 define time_cmd
21     $(call chk_file_notext,$2)
22     $(CHMOD) u+x $2
23     $(TIME) -f"$1: %E" -o $3 ./$2 >$(DEV_NULL) 2>&1
24 endef
25
26 # テスト実行コマンド。引数は、コマンドファイル、出力ファイル、エラーファイル
27 # コマンドファイルを実行し、標準出力を出力ファイルに保存。
28 # エラー発生時は、エラー出力を出力ファイルとエラーファイルに保存。
29 # 用例: $(call exec_cmd,file_cmd,file_out,file_err)
30 define exec_cmd
31     $(call chk_file_notext,$1)
32     $(CHMOD) u+x $1
33     ./$1 >>$2 2>$3
34     if test -s $3; then $(CAT) $3 >>$2; fi
35     $(call rm_null,$3)
36 endef
37
38 # 2つのファイルを比較し、差分ファイルを作成
39 # 引数は、2ファイルのリスト、差分ファイル
40 # 用例: $(call diff_files,files,file_out)
41 define diff_files
42     $(DIFF) $1 >$2 2>&1
43     $(call rm_null,$2)
44 endef
45
46 # 差分ファイルの内容をログファイルに出力
47 # 引数は、テスト名、差分ファイル、ログファイル
48 # 用例: $(call test_log,name,file_diff,file_log)
49 define test_log
50     $(call desc_log,$3)
51     if test ! -s $2; then RES=Success; else RES=Failure; fi; $(ECHO) "$1: Test $$RES $(DATE)" >>$3
52     $(ECHO) "Detail in $(CURRDIR)/$(DETAIL_FILE)" >>$3
53 endef
54
55 # NODISPが設定されていない時は、ログファイルを表示
56 # 引数は、ログファイル
57 # 用例: $(call disp_test_log,file_log)
58 define disp_test_log
59     $(if $(NODISP),,$(CAT) $1)
60 endef
61
62 # ファイル群から、ファイル名とファイルの内容を出力
63 # 引数は、対象ファイル群、出力ファイル
64 # 用例: $(call report_files,list_file_target,file_out)
65 define report_files
66     $(call chk_file_ext,$2)
67     $(foreach tfile,$1,$(call report_file,$(tfile),$2))
68 endef
69
70 # ファイル名とファイルの内容を出力
71 # 引数は、対象ファイル、出力ファイル
72 # 用例: $(call report_file,file_target,file_out)
73 define report_file
74     $(call chk_var_null,$1)
75     if test -s $1; then $(ECHO) "== $1 ==" >>$2; $(call echo_hr,$2); cat $1 >>$2; $(call echo_hr,$2); $(ECHO) >>$2; fi
76 endef
77
78 define echo_hr
79     $(ECHO) "----------------------------------------------------------------------" >>$1
80 endef