システムテストの修正
[YACASL2.git] / test / system / dumpword / Test.mk
index 8da44c1..11d4065 100644 (file)
 # make cleantime: "make time" で作成されたファイルをクリア
 # make clean   : "make" で作成されたファイルをクリア
 # make cleanall: "make" と "make set" で作成されたファイルをクリア
-
 SHELL = /bin/bash
 
+######################################################################
+# マクロ
+######################################################################
+
+# 指定されたファイルをチェックし、空の場合は削除
+# 引数は、対象ファイル
+# 用例: $(call rm_null,file_target)
+define rm_null
+    if test ! -s $1; then $(RM) $1; fi
+endef
+
+# 説明ファイルの内容を、指定されたファイルに出力
+# 引数は、出力ファイル
+# 用例: $(call desc_log,file_out)
+define desc_log
+    if test -s $(DESC_FILE); then $(CAT) $(DESC_FILE) >>$1; fi
+endef
+
+# テスト実行の経過時間を、指定されたファイルに出力して表示
+# 引数は、テスト名、コマンドファイル、出力ファイル
+# 用例: $(call time_cmd,file_cmd,file_out)
+define time_cmd
+    if test ! -x $1; then $(CHMOD) u+x $1; fi
+    ($(TIME) ./$1 1>$(DEV_NULL) 2>$(DEV_NULL)) 2>&1 | $(GREP) '^real' >$2
+endef
+
+# テスト実行コマンド。
+# コマンドファイルを実行し、標準出力を指定されたファイルに保存。
+# エラー発生時は、エラー出力を出力ファイルとエラーファイルに保存。
+# 引数は、コマンドファイル、出力ファイル、エラーファイル
+# 用例: $(call exec_cmd,file_cmd,file_out,file_err)
+define exec_cmd
+    if test ! -x $1; then $(CHMOD) u+x $1; fi
+    ./$1 >>$2 2>$3
+    if test -s $3; then $(CAT) $3 >>$2; fi
+    $(SED) -i '' -e "s%$(CURRDIR)%\$$PWD%g" $2
+    $(call rm_null,$3)
+endef
+
+# 2つのファイルを比較し、差分ファイルを作成
+# 引数は、2ファイルのリスト、差分ファイル
+# 用例: $(call diff_files,files,file_out)
+define diff_files
+    $(DIFF) $1 >$2 2>&1
+    $(call rm_null,$2)
+endef
+
+# 差分ファイルの内容をログファイルに出力
+# 引数は、テスト名、差分ファイル、ログファイル
+# 用例: $(call test_log,name,file_diff,file_log)
+define test_log
+    $(call desc_log,$3)
+    if test ! -s $2; then RES=Success; else RES=Failure; fi; $(ECHO) "$1: Test $$RES $(DATE)" >>$3
+    $(ECHO) "Details in $(CURRDIR)/$(DETAIL_FILE)" >>$3
+endef
+
+# NODISPが設定されていない時は、ログファイルを表示
+# 引数は、ログファイル
+# 用例: $(call disp_test_log,file_log)
+define disp_test_log
+    $(if $(NODISP),,$(CAT) $1)
+endef
+
+# ファイル群から、ファイル名とファイルの内容を指定されたファイルに出力
+# 引数は、対象ファイル群、出力ファイル
+# 用例: $(call report_files,list_file_target,file_out)
+define report_files
+    $(foreach tfile,$1,$(call report_file,$(tfile),$2))
+endef
+
+# ファイル名とファイルの内容を指定されたファイルに出力
+# 引数は、対象ファイル、出力ファイル
+# 用例: $(call report_file,file_target,file_out)
+define report_file
+    $(call chk_var_null,$1)
+    if test -s $1; then $(ECHO) "== $1 ==" >>$2; $(call echo_hr,$2); cat $1 >>$2; $(call echo_hr,$2); $(ECHO) >>$2; fi
+endef
+
+define echo_hr
+    $(ECHO) "----------------------------------------------------------------------" >>$1
+endef
+
 # テスト名。カレントディレクトリー名から取得
 TEST = $(notdir $(CURRDIR))
 
 # コマンドファイルのソース
-CMDSRC_FILE := $(CMD_FILE)
-#CMDSRC_FILE := $(CMD_FILE).c
+CMDSRC_FILE ?= $(CMD_FILE)
 
-.PHONY: check set reset time cleantime clean cleanall
+.PHONY: check set reset clean cleanall time cleantime
 
 check: clean $(DETAIL_FILE)
        @$(call disp_test_log,$(LOG_FILE))
@@ -31,16 +111,14 @@ checkall: clean $(DETAIL_FILE) $(TIME_FILE)
        @$(CAT) $(TIME_FILE) >>$(LOG_FILE)
        @$(call disp_test_log,$(LOG_FILE))
 
-set:
+set: $(CMD_FILE)
+       @$(call chk_file_ext,$(TEST0_FILE))
        @-$(call exec_cmd,$(CMD_FILE),$(TEST0_FILE),$(ERR_FILE))
        @$(CAT) $(TEST0_FILE)
 
-reset: cleanall set
-
-time: cleantime $(TIME_FILE)
-
-cleantime:
-       @$(RM) $(TIME_FILE)
+reset: cleanall $(CMD_FILE)
+       @-$(call exec_cmd,$(CMD_FILE),$(TEST0_FILE),$(ERR_FILE))
+       @$(CAT) $(TEST0_FILE)
 
 clean:
        @$(RM) $(TEST_RES_FILES)
@@ -48,6 +126,12 @@ clean:
 cleanall: clean
        @$(RM) $(TEST0_FILE)
 
+time: cleantime $(TIME_FILE)
+       @$(CAT) $(TIME_FILE)
+
+cleantime:
+       @$(RM) $(TIME_FILE)
+
 $(TEST1_FILE): $(CMD_FILE)
        @-$(call exec_cmd,$^,$@,$(ERR_FILE))
 
@@ -61,4 +145,4 @@ $(DETAIL_FILE): $(LOG_FILE)
        @$(call report_files,$(LOG_FILE) $(CMDSRC_FILE) $(TEST0_FILE) $(ERR_FILE) $(DIFF_FILE) $(TEST1_FILE),$@)
 
 $(TIME_FILE): $(CMD_FILE)
-       $(call time_cmd,$^,$@)
+       @$(call time_cmd,$^,$@)