From 7c0ad2713cb8fc152feca4d865ea449aa2fe502b Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Sun, 17 Aug 2025 13:54:43 +0330 Subject: [PATCH] update --- src/bash.ts | 10 ++-------- tests/package-manager-integration.test.ts | 22 ++++++++++++++++++--- tests/shell-integration.test.ts | 24 +++++++++++++++++++---- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/bash.ts b/src/bash.ts index e20b046..7bcb680 100644 --- a/src/bash.ts +++ b/src/bash.ts @@ -42,14 +42,7 @@ __${nameForVar}_complete() { local requestComp out directive # Build the command to get completions - # Use a more compatible approach instead of \${words[@]:1} - local args="" - for (( i=1; i { // If we get here, syntax is valid expect(true).toBe(true); } catch (error) { - throw new Error(`${pm} bash script has syntax errors: ${error}`); + const errorMessage = + error instanceof Error ? error.message : String(error); + + // Provide helpful error message about bash-completion dependency + const helpMessage = ` +${pm} bash script has syntax errors: ${errorMessage} + +This might be due to missing bash-completion dependency. +To fix this, install bash-completion@2: + + brew install bash-completion@2 + +Then source the completion in your shell profile: + echo 'source $(brew --prefix)/share/bash-completion/bash_completion' >> ~/.bashrc +`; + throw new Error(helpMessage); } finally { // Clean up await unlink(scriptPath).catch(() => {}); @@ -125,9 +140,10 @@ describe('package manager integration tests', () => { const command = `pnpm tsx bin/cli.ts ${pm} bash`; const { stdout } = await exec(command); - // Check for the actual problematic bash syntax in the requestComp assignment - expect(stdout).not.toMatch(/requestComp="[^"]*\$\{words\[@\]:1\}/); // Should not use ${words[@]:1} in requestComp + // Check that it uses the correct ${words[@]:1} syntax (requires bash-completion@2) + expect(stdout).toContain('${words[@]:1}'); // Should use ${words[@]:1} (requires bash-completion@2) expect(stdout).toContain('complete -F'); // Should register completion properly + expect(stdout).toContain('_get_comp_words_by_ref'); // Should use bash-completion functions // Should contain package manager specific function expect(stdout).toMatch( diff --git a/tests/shell-integration.test.ts b/tests/shell-integration.test.ts index ee40e1b..8506dca 100644 --- a/tests/shell-integration.test.ts +++ b/tests/shell-integration.test.ts @@ -78,7 +78,22 @@ describe('shell integration tests', () => { // If we get here, syntax is valid expect(true).toBe(true); } catch (error) { - throw new Error(`Bash script has syntax errors: ${error}`); + const errorMessage = + error instanceof Error ? error.message : String(error); + + // Provide helpful error message about bash-completion dependency + const helpMessage = ` +Bash script has syntax errors: ${errorMessage} + +This might be due to missing bash-completion dependency. +To fix this, install bash-completion@2: + + brew install bash-completion@2 + +Then source the completion in your shell profile: + echo 'source $(brew --prefix)/share/bash-completion/bash_completion' >> ~/.bashrc +`; + throw new Error(helpMessage); } finally { // Clean up await unlink(scriptPath).catch(() => {}); @@ -224,14 +239,15 @@ describe('shell integration tests', () => { // Test for potential bash issues (related to the user's problem) describe('bash-specific issue detection', () => { - it('should generate bash script with proper escaping', async () => { + it('should generate bash script with proper syntax (requires bash-completion@2)', async () => { const command = `pnpm tsx examples/demo.${cliTool}.ts complete bash`; const { stdout } = await exec(command); - // Check for the actual problematic bash syntax in the requestComp assignment - expect(stdout).not.toMatch(/requestComp="[^"]*\$\{words\[@\]:1\}/); // Should not use ${words[@]:1} in requestComp + // Check that it uses the correct ${words[@]:1} syntax + expect(stdout).toContain('${words[@]:1}'); // Should use ${words[@]:1} (requires bash-completion@2) expect(stdout).toContain('requestComp='); // Should have proper variable assignment expect(stdout).toContain('complete -F'); // Should register completion properly + expect(stdout).toContain('_get_comp_words_by_ref'); // Should use bash-completion functions }); it('should generate bash script that handles empty parameters correctly', async () => { -- 2.51.2