Skip to content

Commit 1b48042

Browse files
committed
Added missing copyright headers
1 parent 3bc4ae0 commit 1b48042

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

src/toolchain/toolchain.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,6 @@ export class SwiftToolchain {
548548
break;
549549
}
550550
default: {
551-
// use `type swift` to find `swift`. Run inside /bin/sh to ensure
552-
// we get consistent output as different shells output a different
553-
// format. Tried running with `-p` but that is not available in /bin/sh
554551
swift = await findBinaryPath("swift");
555552
break;
556553
}

src/utilities/shell.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the VS Code Swift open source project
4+
//
5+
// Copyright (c) 2025 the VS Code Swift project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
115
import { execFile } from "./utilities";
216

17+
// use `type swift` to find `swift`. Run inside /bin/sh to ensure
18+
// we get consistent output as different shells output a different
19+
// format. Tried running with `-p` but that is not available in /bin/sh
320
export async function findBinaryPath(binaryName: string): Promise<string> {
421
const { stdout, stderr } = await execFile("/bin/sh", [
522
"-c",

test/unit-tests/utilities/shell.test.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,61 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the VS Code Swift open source project
4+
//
5+
// Copyright (c) 2025 the VS Code Swift project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import { beforeEach, afterEach } from "mocha";
116
import { expect } from "chai";
17+
import * as sinon from "sinon";
218
import { findBinaryPath } from "../../../src/utilities/shell";
19+
import * as utilities from "../../../src/utilities/utilities";
320

421
suite("Shell Unit Test Suite", () => {
22+
let execFileStub: sinon.SinonStub;
23+
24+
beforeEach(() => {
25+
execFileStub = sinon.stub(utilities, "execFile");
26+
});
27+
28+
afterEach(() => {
29+
sinon.restore();
30+
});
31+
532
suite("findBinaryPath", () => {
633
test("returns the path to a binary in the PATH", async () => {
34+
execFileStub.resolves({
35+
stdout: "node is /usr/local/bin/node\n",
36+
stderr: "",
37+
});
38+
739
const binaryPath = await findBinaryPath("node");
8-
expect(binaryPath).to.be.a("string");
9-
expect(binaryPath).to.include("node");
40+
expect(binaryPath).to.equal("/usr/local/bin/node");
41+
expect(execFileStub).to.have.been.calledWith("/bin/sh", [
42+
"-c",
43+
"LC_MESSAGES=C type node",
44+
]);
1045
});
1146

1247
test("throws for a non-existent binary", async () => {
48+
execFileStub.resolves({
49+
stdout: "",
50+
stderr: "sh: type: nonexistentbinary: not found\n",
51+
});
52+
1353
try {
1454
await findBinaryPath("nonexistentbinary");
1555
expect.fail("Expected an error to be thrown for a non-existent binary");
1656
} catch (error) {
1757
expect(error).to.be.an("error");
58+
expect((error as Error).message).to.include("nonexistentbinary");
1859
}
1960
});
2061
});

0 commit comments

Comments
 (0)