Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mass-0910 committed Aug 17, 2022
2 parents 883ba4a + b0c5d34 commit 6afd80a
Show file tree
Hide file tree
Showing 20 changed files with 638 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
hsptmp
packfile
*.exe
*.dll
*.dll
*tmp*
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ hsptestで実行されるテストは、テスト一つに対して一つのサ

テストごとにhsp3clランタイムのインスタンスが起動するため、他のテストサブルーチンで発生した変数代入やエラーなどは現在実行してるテストサブルーチンには影響しません。テストサブルーチン内でなにかのエラーが発生した場合、またはassertionが失敗したとき、そのテストは失敗となります。

hsptestが実行終了すると、以下のような出力がされます。テストサブルーチンのラベル名、テスト結果、エラー行数、エラーの種類、pass/failの数が表示されます
hsptestが実行終了すると、以下のような出力がされます。テストサブルーチンのラベル名、テスト結果、エラー行数、エラーの種類、pass/failの数、テストに掛かった時間が表示されます
```
HSP 3.6.0.7, hsptest 0.4
test1@test_example.hsp: PASS
test2@test_example.hsp: PASS
test3@test_example.hsp: FAIL at line 22: Divided by 0
======= 1 failed, 2 passed =======
test3@test_example.hsp: FAIL at line 22 of test_example.hsp: Divided by 0
======= 1 failed, 2 passed in 0.27 seconds =======
```

## `assertion.as`の使い方
Expand Down
6 changes: 6 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# encoing Shift-JIS
_PRODUCTVERSION=0.4
Comments=HSP3�e�X�g�t���[�����[�N
FileDescription=HSP3�e�X�g�t���[�����[�N���s�t�@�C��
LegalCopyright=(c)2022 mass-0910
ProductName=hsptest
134 changes: 134 additions & 0 deletions append_data.hsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#ifndef append_data_hsp_included
#define append_data_hsp_included

#include "result_format.as"

#module

#define SUCCESS 1
#define FAILURE 0

#defcfunc is_name_alphabet int ch
return ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ('0' <= ch && ch <= '9') || ch == '_'

#defcfunc is_space int ch
return ch == ' ' || ch == '\t'

#defcfunc is_entry_inst str line_str
index = 0
init_status = 1
line_str_buf = line_str
status = init_status
result = SUCCESS
entry_inst = "deffunc defcfunc modfunc modcfunc modinit modterm"
split entry_inst, " ", entry_inst_list
repeat
ch = peek(line_str_buf, index)
if status == 1 {
if ch == '*' {
status = 2
} else : if ch == '#' {
status = 6
} else : if is_space(ch) {
status = 1
} else {
result = FAILURE
}
} else : if status == 2 {
if is_name_alphabet(ch) {
status = 3
} else {
result = FAILURE
}
} else : if status == 3 {
if is_name_alphabet(ch) {
status = 3
} else : if is_space(ch) {
status = 4
} else {
result = FAILURE
}
} else : if status == 4 {
if is_space(ch) == 0 {
result = FAILURE
}
} else : if status == 6 {
repeat length(entry_inst_list)
if instr(line_str_buf, index, entry_inst_list(cnt)) == 0 {
status = 7
index += strlen(entry_inst_list(cnt)) - 1
break
}
loop
if status == 6 : result = FAILURE
} else : if status == 7 {
if is_space(ch) {
status = 8
} else {
result = FAILURE
}
} else : if status == 8 {
// success
}
if result == FAILURE : break
index++
if index >= strlen(line_str_buf) : break
loop
return result

#defcfunc is_multi_line str line_str
line_str_buf = line_str
result = 0
repeat strlen(line_str_buf)
ch = peek(line_str_buf, strlen(line_str_buf) - 1 - cnt)
if is_space(ch) : continue
if ch == '\\' {
result = 1
break
}
break
loop
return result

#deffunc copy_with_edit str src_file_path, str dest_file_path
notesel buf
noteload src_file_path
file_line_num = noteinfo(0)
reading_index = 0
ignore_multiline_str = 0
ignore_multiline_inst = 0
repeat
notesel buf
; if cnt >= noteinfo(0) : break
if cnt > file_line_num : break
noteget l, reading_index
reading_index++
if ignore_multiline_str == 0 && ignore_multiline_inst == 0{
if reading_index - 1 >= noteinfo(0) {
p = -1
} else {
p = reading_index - 1
}
now_line_num = cnt + 1
noteadd "__errfile@ = __file__ : __errline@ = " + now_line_num, p
reading_index++
}
ignore_multiline_inst = 0
// マルチライン文字列には挿入しない
if ignore_multiline_str == 0 && instr(l, 0, "{\"") != -1 && instr(l, 0, "\"}") == -1 {
ignore_multiline_str = 1
}
if ignore_multiline_str && instr(l, 0, "{\"") == -1 && instr(l, 0, "\"}") != -1 {
ignore_multiline_str = 0
}
if ignore_multiline_str == 0 && is_multi_line(l) {
ignore_multiline_inst = 1
}
loop
notesel buf
notesave dest_file_path
return

#global

#endif
21 changes: 16 additions & 5 deletions common/assertion.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#define __init_msg "Assertion was failed"
#define assertTrue(%1, %2=__init_msg) if (%1)==0:mes "&RESULT&{"+"FAIL"+","+__line__+",42,"+%2+"}":return
#define assertFalse(%1, %2=__init_msg) if (%1)!=0:mes "&RESULT&{"+"FAIL"+","+__line__+",42,"+%2+"}":return
#define assertEqual(%1, %2, %3=__init_msg) if (%1)!=(%2):mes "&RESULT&{"+"FAIL"+","+__line__+",42,"+%3+"}":return
#define assertNear(%1, %2, %3=0.0001, %4=__init_msg) if absf(double(%1)-double(%2))>(%3):mes "&RESULT&{"+"FAIL"+","+__line__+",42,"+%4+"}":return
#ifndef assertion_as_included
#define assertion_as_included

#include "result_format.as"

#module

#define global __init_msg "Assertion was failed"
#define global assertTrue(%1, %2=__init_msg) __errline_a=__errline@:__errfile_a=__errfile@:if (%1)==0:mes get_fail_result_format(__errline_a,__errfile_a,%2):return
#define global assertFalse(%1, %2=__init_msg) __errline_a=__errline@:__errfile_a=__errfile@:if (%1)!=0:mes get_fail_result_format(__errline_a,__errfile_a,%2):return
#define global assertEqual(%1, %2, %3=__init_msg) __errline_a=__errline@:__errfile_a=__errfile@:if (%1)!=(%2):mes get_fail_result_format(__errline_a,__errfile_a,%3):return
#define global assertNear(%1, %2, %3=0.0001, %4=__init_msg) __errline_a=__errline@:__errfile_a=__errfile@:if absf(double(%1)-double(%2))>(%3):mes get_fail_result_format(__errline_a,__errfile_a,%3):return

#global

#endif
55 changes: 55 additions & 0 deletions common/result_format.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef result_format_as_included
#define result_format_as_included

#module

/*
成功時のstdout文字列を返す
返り値
成功時のstdout文字列
*/
#defcfunc get_pass_result_format
return "&RESULT&{PASS,0,#,#}"

/*
失敗時のstdout文字列を返す
引数
error_line: エラー発生行数
error_message: エラーメッセージ
返り値
失敗時のstdout文字列
*/
#defcfunc get_fail_result_format int error_line, str error_file, str error_message
return "&RESULT&{FAIL," + error_line + "," + error_file + "," + error_message + "}"

/*
stdoutから結果をパースする
引数
stdout: hspランタイムから出力された文字列
result: 結果("PASS"または"FAIL")を格納する変数
error_line: エラーが発生した行数を格納する変数
error_message: エラーメッセージを格納する変数
removed_stdout: 特殊フォーマット文字列を全て取り除いた標準出力が格納される変数
*/
#deffunc parse_result_format str stdout, var result, var error_line, var error_file, var error_message, var removed_stdout
buf = stdout
notesel buf
resline = notefind("&RESULT&", 1)
noteget resultstr, resline
notedel resline
notedel resline
removed_stdout = buf
resultstr = strmid(resultstr, 9, 1024)
resultstr = strtrim(resultstr, , '}')
getstr result, resultstr, 0, ','
i = strsize
getstr error_line, resultstr, i, ','
i += strsize
getstr error_file, resultstr, i, ','
i += strsize
getstr error_message, resultstr, i, ','
return

#global

#endif
10 changes: 8 additions & 2 deletions common/test.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifndef test_as_included
#define test_as_included

#runtime "hsp3cl"
#include "result_format.as"

goto *__test_as_end

Expand All @@ -8,7 +12,9 @@ goto *__test_as_end
return

*__error
mes "&RESULT&{" + "FAIL" + "," + lparam + "," + wparam + "," + errmsg(wparam - 1) + "}"
mes get_fail_result_format(__errline@, __errfile@, errmsg(wparam - 1))
end wparam

*__test_as_end
*__test_as_end

#endif
40 changes: 40 additions & 0 deletions compile.hsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// hsptest.hspをexeにコンパイルするためのスクリプト

#runtime "hsp3cl"
#packopt name "compile"
#packopt orgpath 0
#packopt version "VERSION"
#include "hspcmp.as"

*init
fname = "./hsptest.hsp"

*mkstart

srcdir=getpath(fname,32+16)
srcname=getpath(fname,1+8+16)

chdir srcdir

mes "Compiling..."+fname

objname="start.ax" ; output object file
cmpmode=0
ppmode=4

hsc_ini srcname+".hsp"
hsc_objname objname
hsc_comp cmpmode,ppmode,0
res=stat:if res!=0 : dialog "ERROR" : goto *goerror

mes "Make .exe file..."
mes srcname
hsc3_make dirinfo(1)+"\\"+srcname+".dpm",1

mes "Done."
end 0

*goerror
hsc_getmes mesbuf
mes mesbuf
end 1
Loading

0 comments on commit 6afd80a

Please sign in to comment.