Skip to content

Commit

Permalink
Ignore subsequent lines of output in 'clangd --version' (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
HighCommander4 authored Oct 23, 2022
1 parent c2aa9b6 commit f936297
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async function installed(clangdPath: string): Promise<semver.Range> {
throw new Error(`Cannot compare vendor's clangd version: ${output}`);
}
// Some vendors add trailing ~patchlevel, ignore this.
const rawVersion = output.substr(pos + prefix.length).split(/ |~/, 1)[0];
const rawVersion = output.substr(pos + prefix.length).split(/\s|~/, 1)[0];
return new semver.Range(rawVersion, loose);
}

Expand Down
8 changes: 8 additions & 0 deletions test/assets/fake-clangd-16/clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
if [ X"$1" = X"--version" ]; then
echo "clangd version 16.0.0"
echo "Features: linux"
else
echo "Unexpected usage"
exit 1
fi
14 changes: 11 additions & 3 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import * as tmp from 'tmp-promise';
import * as install from '../src/index';

const oldClangd = process.cwd() + '/test/assets/fake-clangd-5/clangd';
const newClangd = process.cwd() + '/test/assets/fake-clangd-15/clangd';
const newClangdV15 = process.cwd() + '/test/assets/fake-clangd-15/clangd';
const newClangdV16 = process.cwd() + '/test/assets/fake-clangd-16/clangd';
const unversionedClangd =
process.cwd() + '/test/assets/fake-clangd-unversioned/clangd';
const appleClangd = process.cwd() + '/test/assets/apple-clangd-5/clangd';
Expand Down Expand Up @@ -191,7 +192,14 @@ test('update: from 5 to 10', async (assert, ui) => {
});

test('update: from 15 to 10', async (assert, ui) => {
ui.clangdPath = newClangd;
ui.clangdPath = newClangdV15;
await install.checkUpdates(true, ui);

assert.deepEqual(ui.events, [/*up-to-date*/ 'info']);
});

test('update: from 16 to 10', async (assert, ui) => {
ui.clangdPath = newClangdV16;
await install.checkUpdates(true, ui);

assert.deepEqual(ui.events, [/*up-to-date*/ 'info']);
Expand Down Expand Up @@ -257,7 +265,7 @@ test('prepare: old clangd installed, new unavailable', async (assert, ui) => {
});

test('prepare: new clangd installed', async (assert, ui) => {
ui.clangdPath = newClangd;
ui.clangdPath = newClangdV15;
const status = await install.prepare(ui, true);
await status.background;

Expand Down

0 comments on commit f936297

Please sign in to comment.