Skip to content

Commit 73640d7

Browse files
committed
test(terminal): add test case for forceful rm command
- Add a new test case to check if the safety check correctly identifies the 'rm -f' command as dangerous - Remove redundant comments and refactor existing test cases for better readability
1 parent d3a109e commit 73640d7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

exts/ext-terminal/src/test/kotlin/cc/unitmesh/terminal/sketch/ShellSyntaxSafetyCheckTest.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class ShellSyntaxSafetyCheckTest : BasePlatformTestCase() {
66
fun testCheckDangerousCommandByPsi() {
77
val project = project // Use the test fixture's project
88

9-
// Test safe commands
109
val safeCommands = listOf(
1110
"ls -la",
1211
"cd /home/user",
@@ -19,7 +18,6 @@ class ShellSyntaxSafetyCheckTest : BasePlatformTestCase() {
1918
assertEquals("", result.second)
2019
}
2120

22-
// Test dangerous commands
2321
val dangerousCommands = mapOf(
2422
"rm -rf /tmp" to "Dangerous rm command detected",
2523
"sudo rm file.txt" to "Removing files with elevated privileges",
@@ -35,10 +33,15 @@ class ShellSyntaxSafetyCheckTest : BasePlatformTestCase() {
3533
assertEquals(expectedMessage, result.second)
3634
}
3735

38-
// Test fork bomb
3936
val forkBomb = ":(){ :|:& };:"
4037
val result = ShellSyntaxSafetyCheck.checkDangerousCommand(project, forkBomb)
4138
assertTrue("Fork bomb should be detected", result.first)
4239
assertEquals("Potential fork bomb", result.second)
4340
}
41+
42+
fun testCheckDangerousCommandByPsiWithForce() {
43+
val result = ShellSyntaxSafetyCheck.checkDangerousCommand(project, "rm -f /tmp")
44+
assertTrue("Should be dangerous: rm -f /tmp", result.first)
45+
assertEquals("Dangerous rm command detected", result.second)
46+
}
4447
}

0 commit comments

Comments
 (0)