Skip to content

Commit

Permalink
Merge pull request #108 from augustocdias/fix_107
Browse files Browse the repository at this point in the history
Fix #107
  • Loading branch information
MarcelRobitaille authored Oct 2, 2024
2 parents 29a0cf8 + 6e32f7c commit 0d3ed6e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [1.12.1] 2024-10-02

- Fix errors with default values (#107)

## [1.12.0] 2024-09-30

- Add support for custom values (#33)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Tasks Shell Input",
"description": "Use shell commands as input for your tasks",
"icon": "icon.png",
"version": "1.12.0",
"version": "1.12.1",
"publisher": "augustocdias",
"repository": {
"url": "https://github.com/augustocdias/vscode-shell-command"
Expand Down
19 changes: 19 additions & 0 deletions src/lib/CommandHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,25 @@ describe("Errors", async () => {
expect(() => handler.handle()).rejects.toThrowError(
"The command for input 'inputTest' returned empty result.");
});

test("It should NOT trigger an error with defaultOptions", async () => {
const testDataPath = path.join(__dirname, "../test/testData/errors");

const tasksJson = await import(path.join(testDataPath, ".vscode/tasks.json"));
const mockData = (await import(path.join(testDataPath, "mockData.ts"))).default;

mockVscode.setMockData(mockData);
const input = tasksJson.inputs[1].args;
const handler = new CommandHandler(
input,
new UserInputContext(),
mockExtensionContext as unknown as vscode.ExtensionContext,
child_process,
);

expect(() => handler.handle()).rejects.not.toThrowError(
"The command for input 'inputTest' returned empty result.");
});
});

describe("Argument parsing", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class CommandHandler {
result += stderr;
}

if (result.trim().length == 0) {
if ((result.trim().length == 0) && (undefined === this.args.defaultOptions)) {
throw new ShellCommandException(`The command for input '${this.input.id}' returned empty result.`);
}

Expand Down
15 changes: 15 additions & 0 deletions src/test/testData/errors/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"type": "shell",
"command": "echo ${input:inputTest}",
"problemMatcher": []
},
{
"label": "This should not trigger an error",
"type": "shell",
"command": "echo ${input:inputTestWithDefaults}",
"problemMatcher": []
}
],
"inputs": [
Expand All @@ -22,6 +28,15 @@
"PROJECT": "${workspaceFolderBasename}"
}
}
},
{
"id": "inputTestWithDefaults",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "echo ''",
"defaultOptions": []
}
}
]
}
Expand Down

0 comments on commit 0d3ed6e

Please sign in to comment.