Test the command extraction logic.
()
| 95 | |
| 96 | |
| 97 | def test_extract_commands(): |
| 98 | """Test the command extraction logic.""" |
| 99 | print("\nTesting command extraction:\n") |
| 100 | passed = 0 |
| 101 | failed = 0 |
| 102 | |
| 103 | test_cases = [ |
| 104 | ("ls -la", ["ls"]), |
| 105 | ("npm install && npm run build", ["npm", "npm"]), |
| 106 | ("cat file.txt | grep pattern", ["cat", "grep"]), |
| 107 | ("/usr/bin/node script.js", ["node"]), |
| 108 | ("VAR=value ls", ["ls"]), |
| 109 | ("git status || git init", ["git", "git"]), |
| 110 | # Fallback parser test: complex nested quotes that break shlex |
| 111 | ('docker exec container php -r "echo \\"test\\";"', ["docker"]), |
| 112 | ] |
| 113 | |
| 114 | for cmd, expected in test_cases: |
| 115 | result = extract_commands(cmd) |
| 116 | if result == expected: |
| 117 | print(f" PASS: {cmd!r} -> {result}") |
| 118 | passed += 1 |
| 119 | else: |
| 120 | print(f" FAIL: {cmd!r}") |
| 121 | print(f" Expected: {expected}, Got: {result}") |
| 122 | failed += 1 |
| 123 | |
| 124 | return passed, failed |
| 125 | |
| 126 | |
| 127 | def test_validate_chmod(): |
no test coverage detected