Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CLI --version test to use version from the binary not package.json #626

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import tape from 'tape';
import spawn from 'tape-spawn';
import * as path from 'path';
const pkg = require('../package.json');
import solc from '../';

tape('CLI', function (t) {
t.test('--version', function (st) {
const spt = spawn(st, './solc.js --version');
spt.stdout.match(RegExp(pkg.version + '(-[^a-zA-A0-9.+]+)?(\\+[^a-zA-Z0-9.-]+)?'));
Copy link
Member Author

@cameel cameel May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This old regex actually seems very broken. Given that the string it's meant to match is something like 0.8.10+commit.fc410830.Emscripten.clang:

  • A-A should probably have been A-Z.
  • The character groups should not be negated with ^.
  • pkg.version contains dots, which are interpreted as any character, not literal dots.

I think that only reason this regex "worked" is that these broken parts are marked as optional (?) and the regex was not anchored with ^ and $. So really anything after the version was being accepted.

spt.stdout.match(solc.version() + '\n');
spt.stdout.match(/^\s*[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?\+commit\.[0-9a-f]+([a-zA-Z0-9.-]+)?\s*$/);
spt.stderr.empty();
spt.end();
});
Expand Down