Skip to content

Commit a2641f6

Browse files
committed
[1294] 将相互递归宏崩溃用例 crash_pattern_c 纳入 1294_3.tex 与 1294.py
1 parent d55a4c9 commit a2641f6

5 files changed

Lines changed: 41 additions & 11 deletions

File tree

1294.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
支持用例:
66
- 1294_1.tex: 无参自递归宏 (用例 249)
77
- 1294_2.tex: 带参自递归宏 (用例 289)
8+
- 1294_3.tex: 相互递归宏 (crash_pattern_c)
89
910
启动命令: xmake r stem -d
1011
用法:
11-
python3 1294.py # 默认依序测试 1294_1.tex1294_2.tex
12+
python3 1294.py # 默认依序测试 1294_1.tex, 1294_2.tex, 1294_3.tex
1213
python3 1294.py [path/to.tex] # 测试指定文件
1314
"""
1415

@@ -24,7 +25,12 @@
2425
from pynput.keyboard import Controller as Kbd, Key
2526
from pynput.mouse import Controller as Mouse, Button
2627

27-
HERE = os.path.dirname(os.path.abspath(__file__))
28+
# 定位工程根目录
29+
_cur = os.path.dirname(os.path.abspath(__file__))
30+
while _cur and _cur != "/" and not os.path.isdir(os.path.join(_cur, "TeXmacs")):
31+
_cur = os.path.dirname(_cur)
32+
ROOT_DIR = _cur if _cur else os.path.dirname(os.path.abspath(__file__))
33+
HERE = ROOT_DIR
2834

2935
# 4K (3840x2312) 实测坐标
3036
POS_DOC = (960, 900)
@@ -38,8 +44,9 @@
3844
]
3945

4046
DEFAULT_CASES = [
41-
os.path.join(HERE, "TeXmacs", "tests", "tex", "1294_1.tex"),
42-
os.path.join(HERE, "TeXmacs", "tests", "tex", "1294_2.tex"),
47+
os.path.join(ROOT_DIR, "TeXmacs", "tests", "tex", "1294_1.tex"),
48+
os.path.join(ROOT_DIR, "TeXmacs", "tests", "tex", "1294_2.tex"),
49+
os.path.join(ROOT_DIR, "TeXmacs", "tests", "tex", "1294_3.tex"),
4350
]
4451

4552

TeXmacs/tests/python/1294.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
支持用例:
66
- 1294_1.tex: 无参自递归宏 (用例 249)
77
- 1294_2.tex: 带参自递归宏 (用例 289)
8+
- 1294_3.tex: 相互递归宏 (crash_pattern_c)
89
910
启动命令: xmake r stem -d
1011
用法:
11-
python3 1294.py # 默认依序测试 1294_1.tex1294_2.tex
12+
python3 1294.py # 默认依序测试 1294_1.tex, 1294_2.tex, 1294_3.tex
1213
python3 1294.py [path/to.tex] # 测试指定文件
1314
"""
1415

@@ -24,7 +25,12 @@
2425
from pynput.keyboard import Controller as Kbd, Key
2526
from pynput.mouse import Controller as Mouse, Button
2627

27-
HERE = os.path.dirname(os.path.abspath(__file__))
28+
# 定位工程根目录
29+
_cur = os.path.dirname(os.path.abspath(__file__))
30+
while _cur and _cur != "/" and not os.path.isdir(os.path.join(_cur, "TeXmacs")):
31+
_cur = os.path.dirname(_cur)
32+
ROOT_DIR = _cur if _cur else os.path.dirname(os.path.abspath(__file__))
33+
HERE = ROOT_DIR
2834

2935
# 4K (3840x2312) 实测坐标
3036
POS_DOC = (960, 900)
@@ -38,8 +44,9 @@
3844
]
3945

4046
DEFAULT_CASES = [
41-
os.path.join(HERE, "TeXmacs", "tests", "tex", "1294_1.tex"),
42-
os.path.join(HERE, "TeXmacs", "tests", "tex", "1294_2.tex"),
47+
os.path.join(ROOT_DIR, "TeXmacs", "tests", "tex", "1294_1.tex"),
48+
os.path.join(ROOT_DIR, "TeXmacs", "tests", "tex", "1294_2.tex"),
49+
os.path.join(ROOT_DIR, "TeXmacs", "tests", "tex", "1294_3.tex"),
4350
]
4451

4552

TeXmacs/tests/tex/1294_3.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\newcommand{\macroA}{\macroB}
2+
\newcommand{\macroB}{\macroA}
3+
\macroA

devel/1294.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## What
1515

16-
- 新增 C++ 回归测试 `tests/Plugins/Tex/parsetex_test.cpp`(包含用例 249 与 289)。
16+
- 新增 C++ 回归测试 `tests/Plugins/Tex/parsetex_test.cpp`(包含用例 249、289pattern_c)。
1717
- 新增自动化 GUI 回归测试脚本 `TeXmacs/tests/python/1294.py`(以及根目录 `1294.py`)。
1818
- 落实「排版引擎」+「LaTeX 转换」双层防御:
1919
1. 排版引擎层:`concater_rep::typeset_compound``typeset_auto` 增加宏展开深度限制,超限降级为占位 box,防止任何宏递归引起栈溢出崩溃。
@@ -56,9 +56,10 @@
5656
- `src/Typeset/Concat/concat_macro.cpp`
5757
- `src/Plugins/Tex/fromtex_post.cpp`
5858
- `src/Graphics/Fonts/find_font.cpp`
59-
- `tests/Plugins/Tex/parsetex_test.cpp`(回归测试,含 249 与 289 用例)
59+
- `tests/Plugins/Tex/parsetex_test.cpp`(回归测试,含 249、2891294_3 用例)
6060
- `TeXmacs/tests/tex/1294_1.tex`(用例 249 样本)
6161
- `TeXmacs/tests/tex/1294_2.tex`(用例 289 样本)
62+
- `TeXmacs/tests/tex/1294_3.tex`(用例 crash_pattern_c 相互递归样本)
6263
- `TeXmacs/tests/python/1294.py`(自动化 GUI 粘贴回归测试脚本)
6364
- `1294.py`
6465

@@ -72,7 +73,7 @@ xmake r 0631
7273

7374
# 2. GUI 自动化测试
7475
python3 1294.py
75-
# 预期:1294_1.tex 和 1294_2.tex 均 PASS,进程不退出、无垃圾内容插入
76+
# 预期:1294_1.tex、1294_2.tex1294_3.tex 均 PASS,进程不退出、无垃圾内容插入
7677
```
7778

7879
### 手动测试方法

tests/Plugins/Tex/parsetex_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private slots:
3131
void cleanupTestCase ();
3232
void test_crash_case_249 ();
3333
void test_crash_case_289 ();
34+
void test_crash_case_1294_3 ();
3435
};
3536

3637
void
@@ -78,5 +79,16 @@ TestParseTex::test_crash_case_289 () {
7879
QVERIFY (is_func (doc, moebius::DOCUMENT));
7980
}
8081

82+
void
83+
TestParseTex::test_crash_case_1294_3 () {
84+
// 相互递归宏定义用例 (crash_pattern_c),复现代码 TeXmacs/tests/tex/1294_3.tex
85+
string s;
86+
QVERIFY2 (
87+
!load_string (url_system ("$TEXMACS_PATH/tests/tex/1294_3.tex"), s, true),
88+
"cannot load 1294_3.tex");
89+
tree doc= latex_document_to_tree (s);
90+
QVERIFY (is_func (doc, moebius::DOCUMENT));
91+
}
92+
8193
QTEST_MAIN (TestParseTex)
8294
#include "parsetex_test.moc"

0 commit comments

Comments
 (0)