From fa4bbfa92a1e7253f17a37a32f6de52209c67fd4 Mon Sep 17 00:00:00 2001 From: DouZhichong Date: Fri, 12 Dec 2025 11:10:34 +0800 Subject: [PATCH] add ecj test cases --- docs/system_base/ecj/tc_ecj_test_fun001.yaml | 23 ++++++ docs/system_base/ecj/tc_ecj_test_fun002.yaml | 23 ++++++ docs/system_base/ecj/tc_ecj_test_fun003.yaml | 24 ++++++ docs/system_base/ecj/tc_ecj_test_fun004.yaml | 34 ++++++++ docs/system_base/ecj/tc_ecj_test_fun005.yaml | 26 ++++++ docs/system_base/ecj/tc_ecj_test_fun006.yaml | 37 +++++++++ docs/system_base/ecj/tc_ecj_test_fun007.yaml | 33 ++++++++ tests/system_base/ecj/tc_ecj_test_fun001.py | 42 ++++++++++ tests/system_base/ecj/tc_ecj_test_fun002.py | 58 ++++++++++++++ tests/system_base/ecj/tc_ecj_test_fun003.py | 63 +++++++++++++++ tests/system_base/ecj/tc_ecj_test_fun004.py | 84 ++++++++++++++++++++ tests/system_base/ecj/tc_ecj_test_fun005.py | 67 ++++++++++++++++ tests/system_base/ecj/tc_ecj_test_fun006.py | 84 ++++++++++++++++++++ tests/system_base/ecj/tc_ecj_test_fun007.py | 68 ++++++++++++++++ 14 files changed, 666 insertions(+) create mode 100644 docs/system_base/ecj/tc_ecj_test_fun001.yaml create mode 100644 docs/system_base/ecj/tc_ecj_test_fun002.yaml create mode 100644 docs/system_base/ecj/tc_ecj_test_fun003.yaml create mode 100644 docs/system_base/ecj/tc_ecj_test_fun004.yaml create mode 100644 docs/system_base/ecj/tc_ecj_test_fun005.yaml create mode 100644 docs/system_base/ecj/tc_ecj_test_fun006.yaml create mode 100644 docs/system_base/ecj/tc_ecj_test_fun007.yaml create mode 100644 tests/system_base/ecj/tc_ecj_test_fun001.py create mode 100644 tests/system_base/ecj/tc_ecj_test_fun002.py create mode 100644 tests/system_base/ecj/tc_ecj_test_fun003.py create mode 100644 tests/system_base/ecj/tc_ecj_test_fun004.py create mode 100644 tests/system_base/ecj/tc_ecj_test_fun005.py create mode 100644 tests/system_base/ecj/tc_ecj_test_fun006.py create mode 100644 tests/system_base/ecj/tc_ecj_test_fun007.py diff --git a/docs/system_base/ecj/tc_ecj_test_fun001.yaml b/docs/system_base/ecj/tc_ecj_test_fun001.yaml new file mode 100644 index 0000000000..a4faf23ef4 --- /dev/null +++ b/docs/system_base/ecj/tc_ecj_test_fun001.yaml @@ -0,0 +1,23 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, ecj +用例描述: 测试 ecj Java编译器基础功能及版本信息 +修改人: douzhichong + +前置条件: +- 安装 ecj 软件包 + +测试步骤: +- ## 测试基础命令功能 + - 执行 ecj 命令查看默认输出 [命令: ecj] + - 查看 ecj 版本信息 [命令: ecj -version] + - 查看 ecj 帮助信息 [命令: ecj -help] + - 验证版本信息包含必要标识 [命令: ecj -version | grep -q "Eclipse Compiler for Java"] + +期望结果: +- ecj 命令成功执行(返回码为0) +- 版本信息包含 "Eclipse Compiler for Java" 标识 +- 帮助信息正确显示 \ No newline at end of file diff --git a/docs/system_base/ecj/tc_ecj_test_fun002.yaml b/docs/system_base/ecj/tc_ecj_test_fun002.yaml new file mode 100644 index 0000000000..d8c5cf4490 --- /dev/null +++ b/docs/system_base/ecj/tc_ecj_test_fun002.yaml @@ -0,0 +1,23 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, ecj +用例描述: 测试 ecj Java编译器不同版本兼容性 +修改人: douzhichong + +前置条件: +- 安装 ecj 软件包 + +测试步骤: +- ## 测试不同Java版本编译 + - 创建简单Java测试文件 [内容: public class TestClass { public static void main(String[] args) { System.out.println("Hello from ECJ"); } }] + - 使用 Java 1.8 兼容性编译 [命令: ecj -1.8 -d . TestClass.java] + - 使用 Java 11 兼容性编译 [命令: ecj -11 -d . TestClass.java] + - 使用明确源/目标版本编译 [命令: ecj -source 1.8 -target 1.8 -d . TestClass.java] + - 使用无警告选项编译 [命令: ecj -nowarn -d . TestClass.java] + +期望结果: +- 所有编译命令成功执行(返回码为0) +- 生成的class文件可以正常创建 \ No newline at end of file diff --git a/docs/system_base/ecj/tc_ecj_test_fun003.yaml b/docs/system_base/ecj/tc_ecj_test_fun003.yaml new file mode 100644 index 0000000000..23eb2ec8f0 --- /dev/null +++ b/docs/system_base/ecj/tc_ecj_test_fun003.yaml @@ -0,0 +1,24 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, ecj +用例描述: 测试 ecj Java编译器警告和错误处理选项 +修改人: douzhichong + +前置条件: +- 安装 ecj 软件包 + +测试步骤: +- ## 测试警告处理选项 + - 创建Java测试文件 [内容: public class WarnTest { public void oldMethod() {} public static void main(String[] args) { new WarnTest().oldMethod(); } }] + - 使用 -deprecation 选项编译 [命令: ecj -deprecation WarnTest.java] + - 使用 -warn:none 选项编译 [命令: ecj -warn:none WarnTest.java] + - 使用 -nowarn 选项编译 [命令: ecj -nowarn WarnTest.java] + - 检查 -err 选项支持 [命令: ecj -err:none WarnTest.java] + - 检查 -info 选项支持 [命令: ecj -info:none WarnTest.java] + +期望结果: +- 所有编译命令成功执行(返回码为0) +- 警告处理选项被正确支持 \ No newline at end of file diff --git a/docs/system_base/ecj/tc_ecj_test_fun004.yaml b/docs/system_base/ecj/tc_ecj_test_fun004.yaml new file mode 100644 index 0000000000..e4528a519c --- /dev/null +++ b/docs/system_base/ecj/tc_ecj_test_fun004.yaml @@ -0,0 +1,34 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, ecj +用例描述: 测试 ecj Java编译器调试信息和类路径功能 +修改人: douzhichong + +前置条件: +- 安装 ecj 软件包 + +测试步骤: +- ## 测试调试信息选项 + - 创建调试测试文件 [内容: public class DebugTest { public static void main(String[] args) { int localVar = 42; System.out.println("Debug value: " + localVar); } }] + - 使用全调试信息编译 [命令: ecj -g -d . DebugTest.java] + - 使用特定调试信息编译 [命令: ecj -g:lines,source -d . DebugTest.java] + - 使用无调试信息编译 [命令: ecj -g:none -d . DebugTest.java] + +- ## 测试类路径功能 + - 创建库文件 [内容: public class TestLib { public static void helper() { System.out.println("Helper method"); } }] + - 编译库文件 [命令: ecj TestLib.java] + - 使用类路径编译测试文件 [命令: ecj -cp . DebugTest.java] + +- ## 测试输出目录功能 + - 创建输出目录 [命令: mkdir -p outdir] + - 指定输出目录编译 [命令: ecj -d outdir DebugTest.java] + - 验证输出文件存在 [命令: test -f outdir/DebugTest.class] + +期望结果: +- 所有编译命令成功执行(返回码为0) +- 调试信息选项被正确支持 +- 类路径功能正常工作 +- 输出目录功能正常工作 \ No newline at end of file diff --git a/docs/system_base/ecj/tc_ecj_test_fun005.yaml b/docs/system_base/ecj/tc_ecj_test_fun005.yaml new file mode 100644 index 0000000000..84c5c1b736 --- /dev/null +++ b/docs/system_base/ecj/tc_ecj_test_fun005.yaml @@ -0,0 +1,26 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, ecj +用例描述: 测试 ecj Java编译器高级编译选项 +修改人: douzhichong + +前置条件: +- 安装 ecj 软件包 + +测试步骤: +- ## 测试高级编译选项 + - 创建Java测试文件 [内容: public class ReleaseTest { public static void main(String[] args) { System.out.println("Testing release options"); } }] + - 使用 Java 11 兼容性编译 [命令: ecj -11 ReleaseTest.java] + - 使用明确源/目标版本编译 [命令: ecj -source 11 -target 11 ReleaseTest.java] + - 使用 Java 1.7 兼容性编译 [命令: ecj -1.7 ReleaseTest.java] + - 使用 Java 1.8 兼容性编译 [命令: ecj -1.8 ReleaseTest.java] + - 使用 -preserveAllLocals 选项编译 [命令: ecj -preserveAllLocals ReleaseTest.java] + - 使用 -inlineJSR 选项编译 [命令: ecj -inlineJSR ReleaseTest.java] + - 使用 -enableJavadoc 选项编译 [命令: ecj -enableJavadoc ReleaseTest.java] + +期望结果: +- 所有编译命令成功执行(返回码为0) +- 高级编译选项被正确支持 \ No newline at end of file diff --git a/docs/system_base/ecj/tc_ecj_test_fun006.yaml b/docs/system_base/ecj/tc_ecj_test_fun006.yaml new file mode 100644 index 0000000000..dfe8cb8704 --- /dev/null +++ b/docs/system_base/ecj/tc_ecj_test_fun006.yaml @@ -0,0 +1,37 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, ecj +用例描述: 测试 ecj Java编译器注解处理和配置功能 +修改人: douzhichong + +前置条件: +- 安装 ecj 软件包 + +测试步骤: +- ## 测试注解处理选项 + - 创建Java测试文件 [内容: public class AnnotationTest { public static void main(String[] args) { System.out.println("Testing annotation processing options"); } }] + - 使用 -proc:none 选项编译 [命令: ecj -proc:none AnnotationTest.java] + +- ## 测试配置文件选项 + - 创建配置文件 [内容: # Test properties file for ecj] + - 使用配置文件编译 [命令: ecj -properties ecj.properties AnnotationTest.java] + +- ## 测试编码选项 + - 检查编码选项支持 [命令: ecj -encoding UTF-8 -help] + +- ## 测试参数选项 + - 创建参数测试文件 [内容: public class ParamTest { public void testMethod(String param1, int param2) { System.out.println("Parameters: " + param1 + ", " + param2); } public static void main(String[] args) { new ParamTest().testMethod("test", 123); } }] + - 使用 -parameters 选项编译 [命令: ecj -parameters ParamTest.java] + +- ## 测试注解处理器选项 + - 使用 -A 选项传递参数给注解处理器 [命令: ecj -Akey=value AnnotationTest.java] + +期望结果: +- 所有编译命令成功执行(返回码为0) +- 注解处理选项被正确支持 +- 配置文件功能正常工作 +- 编码选项被正确支持 +- 参数选项正常工作 \ No newline at end of file diff --git a/docs/system_base/ecj/tc_ecj_test_fun007.yaml b/docs/system_base/ecj/tc_ecj_test_fun007.yaml new file mode 100644 index 0000000000..c5d79e9404 --- /dev/null +++ b/docs/system_base/ecj/tc_ecj_test_fun007.yaml @@ -0,0 +1,33 @@ +作者: douzhichong +优先级: P1 +支持架构: noarch +执行方式: 自动 +测试类型: 功能测试 +通用标签: local, ecj +用例描述: 测试 ecj Java编译器性能和诊断功能 +修改人: douzhichong + +前置条件: +- 安装 ecj 软件包 + +测试步骤: +- ## 测试性能诊断选项 + - 创建性能测试文件 [内容: public class PerfTest { public static void main(String[] args) { for (int i = 0; i < 10; i++) { System.out.println("Iteration: " + i); } } }] + - 使用详细输出模式编译 [命令: ecj -verbose PerfTest.java] + - 使用时间统计模式编译 [命令: ecj -time PerfTest.java] + - 使用 -noExit 选项编译 [命令: ecj -noExit PerfTest.java] + - 使用最大问题数限制编译 [命令: ecj -maxProblems 100 PerfTest.java] + +- ## 测试日志功能 + - 使用日志输出编译 [命令: ecj -log ecj_log.xml PerfTest.java] + - 验证日志文件创建 [命令: test -f ecj_log.xml] + +- ## 测试重复编译功能 + - 使用重复编译选项 [命令: ecj -repeat 2 PerfTest.java] + +期望结果: +- 所有编译命令成功执行(返回码为0) +- 详细输出模式正常工作 +- 时间统计功能正常工作 +- 日志文件正确创建 +- 重复编译功能正常工作 \ No newline at end of file diff --git a/tests/system_base/ecj/tc_ecj_test_fun001.py b/tests/system_base/ecj/tc_ecj_test_fun001.py new file mode 100644 index 0000000000..144709a4c3 --- /dev/null +++ b/tests/system_base/ecj/tc_ecj_test_fun001.py @@ -0,0 +1,42 @@ +""" +@File: tc_ecj_test_fun001.py +@Time: 2025/1/14 11:22:30 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_ecj_test_fun001.yaml for details + + :avocado: tags=P1,noarch,local,ecj + """ + PARAM_DIC = {"pkg_name": "ecj"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.files_to_clean = [] + + def test(self): + code, result = self.cmd('ecj') + self.assertEqual(code, 0, "Basic ecj command execution failed") + + code, result = self.cmd('ecj -version') + self.assertEqual(code, 0, "Show ecj version failed") + + code, result = self.cmd('ecj -help') + self.assertEqual(code, 0, "Show ecj help information failed") + + code, result = self.cmd('ecj -version | grep -q "Eclipse Compiler for Java"') + self.assertEqual(code, 0, "Version information does not contain expected text") + + def tearDown(self): + for file in self.files_to_clean: + self.cmd(f'rm -f {file}') + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/ecj/tc_ecj_test_fun002.py b/tests/system_base/ecj/tc_ecj_test_fun002.py new file mode 100644 index 0000000000..ed72eb6481 --- /dev/null +++ b/tests/system_base/ecj/tc_ecj_test_fun002.py @@ -0,0 +1,58 @@ +""" +@File: tc_ecj_test_fun002.py +@Time: 2025/1/14 11:23:15 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_ecj_test_fun002.yaml for details + + :avocado: tags=P1,noarch,local,ecj + """ + PARAM_DIC = {"pkg_name": "ecj"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.files_to_clean = [] + self.dirs_to_clean = [] + + def test(self): + test_java = "TestClass.java" + java_code = """ +public class TestClass { + public static void main(String[] args) { + System.out.println("Hello from ECJ"); + } +} +""" + with open(test_java, 'w') as f: + f.write(java_code) + self.files_to_clean.append(test_java) + self.files_to_clean.append('TestClass.class') + + code, result = self.cmd(f'ecj -1.8 -d . {test_java}') + self.assertEqual(code, 0, "Java 8 compilation failed") + + code, result = self.cmd(f'ecj -11 -d . {test_java}') + self.assertEqual(code, 0, "Java 11 compilation failed") + + code, result = self.cmd(f'ecj -source 1.8 -target 1.8 -d . {test_java}') + self.assertEqual(code, 0, "Explicit source/target compilation failed") + + code, result = self.cmd(f'ecj -nowarn -d . {test_java}') + self.assertEqual(code, 0, "Compilation with -nowarn failed") + + def tearDown(self): + for file in self.files_to_clean: + self.cmd(f'rm -f {file}') + for dir in self.dirs_to_clean: + self.cmd(f'rm -rf {dir}') + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/ecj/tc_ecj_test_fun003.py b/tests/system_base/ecj/tc_ecj_test_fun003.py new file mode 100644 index 0000000000..747e8d622f --- /dev/null +++ b/tests/system_base/ecj/tc_ecj_test_fun003.py @@ -0,0 +1,63 @@ +""" +@File: tc_ecj_test_fun003.py +@Time: 2025/1/14 11:24:00 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_ecj_test_fun003.yaml for details + + :avocado: tags=P1,noarch,local,ecj + """ + PARAM_DIC = {"pkg_name": "ecj"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.files_to_clean = [] + + def test(self): + # 测试警告选项 + warn_java = "WarnTest.java" + warn_code = """ +public class WarnTest { + public void oldMethod() {} + + public static void main(String[] args) { + new WarnTest().oldMethod(); + } +} +""" + with open(warn_java, 'w') as f: + f.write(warn_code) + self.files_to_clean.append(warn_java) + self.files_to_clean.append('WarnTest.class') + + code, result = self.cmd(f'ecj -deprecation {warn_java}') + self.assertEqual(code, 0, "Compilation with -deprecation failed") + + code, result = self.cmd(f'ecj -warn:none {warn_java}') + self.assertEqual(code, 0, "Compilation with -warn:none failed") + + code, result = self.cmd(f'ecj -nowarn {warn_java}') + self.assertEqual(code, 0, "Compilation with -nowarn failed") + + code, result = self.cmd('ecj -help | grep -q "proceedOnError"') + + code, result = self.cmd(f'ecj -err:none {warn_java}') + self.assertEqual(code, 0, "Compilation with -err:none failed") + + code, result = self.cmd(f'ecj -info:none {warn_java}') + self.assertEqual(code, 0, "Compilation with -info:none failed") + + def tearDown(self): + for file in self.files_to_clean: + self.cmd(f'rm -f {file}') + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/ecj/tc_ecj_test_fun004.py b/tests/system_base/ecj/tc_ecj_test_fun004.py new file mode 100644 index 0000000000..ad27ea7e32 --- /dev/null +++ b/tests/system_base/ecj/tc_ecj_test_fun004.py @@ -0,0 +1,84 @@ +""" +@File: tc_ecj_test_fun004.py +@Time: 2025/1/14 11:24:45 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_ecj_test_fun004.yaml for details + + :avocado: tags=P1,noarch,local,ecj + """ + PARAM_DIC = {"pkg_name": "ecj"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.files_to_clean = [] + self.dirs_to_clean = [] + + def test(self): + test_java = "DebugTest.java" + java_code = """ +public class DebugTest { + public static void main(String[] args) { + int localVar = 42; + System.out.println("Debug value: " + localVar); + } +} +""" + with open(test_java, 'w') as f: + f.write(java_code) + self.files_to_clean.append(test_java) + self.files_to_clean.append('DebugTest.class') + + lib_java = "TestLib.java" + lib_code = """ +public class TestLib { + public static void helper() { + System.out.println("Helper method"); + } +} +""" + with open(lib_java, 'w') as f: + f.write(lib_code) + self.files_to_clean.append(lib_java) + self.files_to_clean.append('TestLib.class') + + self.dirs_to_clean.append('outdir') + + code, result = self.cmd(f'ecj -g -d . {test_java}') + self.assertEqual(code, 0, "Compilation with debug info failed") + + code, result = self.cmd(f'ecj -g:lines,source -d . {test_java}') + self.assertEqual(code, 0, "Compilation with specific debug info failed") + + code, result = self.cmd(f'ecj -g:none -d . {test_java}') + self.assertEqual(code, 0, "Compilation with no debug info failed") + + code, result = self.cmd(f'ecj {lib_java}') + self.assertEqual(code, 0, "Library compilation failed") + + code, result = self.cmd(f'ecj -cp . {test_java}') + self.assertEqual(code, 0, "Compilation with classpath failed") + + code, result = self.cmd('mkdir -p outdir') + code, result = self.cmd(f'ecj -d outdir {test_java}') + self.assertEqual(code, 0, "Compilation with output directory failed") + + code, result = self.cmd('test -f outdir/DebugTest.class') + self.assertEqual(code, 0, "Output class file not found") + + def tearDown(self): + for file in self.files_to_clean: + self.cmd(f'rm -f {file}') + for dir in self.dirs_to_clean: + self.cmd(f'rm -rf {dir}') + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/ecj/tc_ecj_test_fun005.py b/tests/system_base/ecj/tc_ecj_test_fun005.py new file mode 100644 index 0000000000..3b44669b45 --- /dev/null +++ b/tests/system_base/ecj/tc_ecj_test_fun005.py @@ -0,0 +1,67 @@ +""" +@File: tc_ecj_test_fun005.py +@Time: 2025/1/14 11:25:30 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_ecj_test_fun005.yaml for details + + :avocado: tags=P1,noarch,local,ecj + """ + PARAM_DIC = {"pkg_name": "ecj"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.files_to_clean = [] + + def test(self): + # 创建简单的Java文件 + test_java = "ReleaseTest.java" + test_code = """ +public class ReleaseTest { + public static void main(String[] args) { + System.out.println("Testing release options"); + } +} +""" + with open(test_java, 'w') as f: + f.write(test_code) + self.files_to_clean.append(test_java) + self.files_to_clean.append('ReleaseTest.class') + + code, result = self.cmd(f'ecj -11 {test_java}') + self.assertEqual(code, 0, "Compilation with Java 11 compliance failed") + + code, result = self.cmd(f'ecj -source 11 -target 11 {test_java}') + self.assertEqual(code, 0, "Compilation with source/target 11 failed") + + code, result = self.cmd(f'ecj -1.7 {test_java}') + self.assertEqual(code, 0, "Compilation with Java 1.7 compliance failed") + + code, result = self.cmd(f'ecj -1.8 {test_java}') + self.assertEqual(code, 0, "Compilation with Java 1.8 compliance failed") + + code, result = self.cmd('ecj -help | grep -q "module"') + + code, result = self.cmd(f'ecj -preserveAllLocals {test_java}') + self.assertEqual(code, 0, "Compilation with -preserveAllLocals failed") + + code, result = self.cmd(f'ecj -inlineJSR {test_java}') + self.assertEqual(code, 0, "Compilation with -inlineJSR failed") + + code, result = self.cmd(f'ecj -enableJavadoc {test_java}') + self.assertEqual(code, 0, "Compilation with -enableJavadoc failed") + + def tearDown(self): + for file in self.files_to_clean: + self.cmd(f'rm -f {file}') + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/ecj/tc_ecj_test_fun006.py b/tests/system_base/ecj/tc_ecj_test_fun006.py new file mode 100644 index 0000000000..4a3e0fbdf5 --- /dev/null +++ b/tests/system_base/ecj/tc_ecj_test_fun006.py @@ -0,0 +1,84 @@ +""" +@File: tc_ecj_test_fun006.py +@Time: 2025/1/14 11:26:15 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_ecj_test_fun006.yaml for details + + :avocado: tags=P1,noarch,local,ecj + """ + PARAM_DIC = {"pkg_name": "ecj"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.files_to_clean = [] + + def test(self): + + test_java = "AnnotationTest.java" + test_code = """ +public class AnnotationTest { + public static void main(String[] args) { + System.out.println("Testing annotation processing options"); + } +} +""" + with open(test_java, 'w') as f: + f.write(test_code) + self.files_to_clean.append(test_java) + self.files_to_clean.append('AnnotationTest.class') + + code, result = self.cmd(f'ecj -proc:none {test_java}') + self.assertEqual(code, 0, "Compilation with proc:none failed") + + prop_file = "ecj.properties" + prop_content = "# Test properties file for ecj\n" + with open(prop_file, 'w') as f: + f.write(prop_content) + self.files_to_clean.append(prop_file) + + code, result = self.cmd(f'ecj -properties {prop_file} {test_java}') + self.assertEqual(code, 0, "Compilation with properties file failed") + + code, result = self.cmd('ecj -encoding UTF-8 -help') + self.assertEqual(code, 0, "Encoding option check failed") + + code, result = self.cmd('ecj -help | grep -q "encoding"') + + param_java = "ParamTest.java" + param_code = """ +public class ParamTest { + public void testMethod(String param1, int param2) { + System.out.println("Parameters: " + param1 + ", " + param2); + } + + public static void main(String[] args) { + new ParamTest().testMethod("test", 123); + } +} +""" + with open(param_java, 'w') as f: + f.write(param_code) + self.files_to_clean.append(param_java) + self.files_to_clean.append('ParamTest.class') + + code, result = self.cmd(f'ecj -parameters {param_java}') + self.assertEqual(code, 0, "Compilation with -parameters failed") + + code, result = self.cmd(f'ecj -Akey=value {test_java}') + self.assertEqual(code, 0, "Compilation with -A option failed") + + def tearDown(self): + for file in self.files_to_clean: + self.cmd(f'rm -f {file}') + super().tearDown(self.PARAM_DIC) \ No newline at end of file diff --git a/tests/system_base/ecj/tc_ecj_test_fun007.py b/tests/system_base/ecj/tc_ecj_test_fun007.py new file mode 100644 index 0000000000..19ba182f1a --- /dev/null +++ b/tests/system_base/ecj/tc_ecj_test_fun007.py @@ -0,0 +1,68 @@ +""" +@File: tc_ecj_test_fun007.py +@Time: 2025/1/14 11:27:00 +@Author: douzhichong +@Version: 1.0 +@Contact: douzhichong@inspur.com +@License: Mulan PSL v2 +@Modify: douzhichong +""" + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_ecj_test_fun007.yaml for details + + :avocado: tags=P1,noarch,local,ecj + """ + PARAM_DIC = {"pkg_name": "ecj"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.files_to_clean = [] + + def test(self): + test_java = "PerfTest.java" + java_code = """ +public class PerfTest { + public static void main(String[] args) { + for (int i = 0; i < 10; i++) { + System.out.println("Iteration: " + i); + } + } +} +""" + with open(test_java, 'w') as f: + f.write(java_code) + self.files_to_clean.append(test_java) + self.files_to_clean.append('PerfTest.class') + + log_file = "ecj_log.xml" + self.files_to_clean.append(log_file) + + code, result = self.cmd(f'ecj -verbose {test_java}') + self.assertEqual(code, 0, "Compilation with verbose output failed") + + code, result = self.cmd(f'ecj -time {test_java}') + self.assertEqual(code, 0, "Compilation with timing failed") + + code, result = self.cmd(f'ecj -noExit {test_java}') + + code, result = self.cmd(f'ecj -maxProblems 100 {test_java}') + self.assertEqual(code, 0, "Compilation with maxProblems failed") + + code, result = self.cmd(f'ecj -log {log_file} {test_java}') + self.assertEqual(code, 0, "Compilation with log file failed") + + code, result = self.cmd(f'test -f {log_file}') + self.assertEqual(code, 0, "Log file not created") + + code, result = self.cmd(f'ecj -repeat 2 {test_java}') + self.assertEqual(code, 0, "Compilation with repeat option failed") + + def tearDown(self): + for file in self.files_to_clean: + self.cmd(f'rm -f {file}') + super().tearDown(self.PARAM_DIC) \ No newline at end of file -- Gitee