More conversions

This commit is contained in:
Matt Godbolt
2024-03-08 21:16:09 -06:00
parent 8cb8c11f32
commit a9e0daa31b
9 changed files with 47 additions and 42 deletions
+1 -1
View File
@@ -169,7 +169,7 @@ export class AsmParser extends AsmRegex implements IAsmParser {
return inVLIWpacket;
}
hasOpcode(line, inNvccCode, inVLIWpacket?) {
hasOpcode(line, inNvccCode?, inVLIWpacket?) {
// Remove any leading label definition...
const match = line.match(this.labelDef);
if (match) {
+4 -2
View File
@@ -219,8 +219,10 @@ describe('Execution tests', async () => {
]);
expect(options).toEqual({});
expect(filenameTransform).toBeTruthy();
expect(filenameTransform('moo')).toEqual('moo');
expect(filenameTransform('/some/custom/cwd/file')).toEqual('/app/file');
if (filenameTransform) {
expect(filenameTransform('moo')).toEqual('moo');
expect(filenameTransform('/some/custom/cwd/file')).toEqual('/app/file');
}
});
it('should handle timeouts', () => {
const args = exec.getNsJailOptions('sandbox', '/path/to/compiler', [], {timeoutMs: 1234}).args;
+1 -1
View File
@@ -25,7 +25,7 @@
import path from 'path';
import {configure, verifyAsJSON} from 'approvals';
import type {ApprovalFailureReporter} from 'approvals/lib/Core/ApprovalFailureReporter';
import type {ApprovalFailureReporter} from 'approvals/lib/Core/ApprovalFailureReporter.js';
import {beforeAll, describe, expect, it} from 'vitest';
import {CC65AsmParser} from '../lib/parsers/asm-parser-cc65.js';
+7 -7
View File
@@ -31,7 +31,7 @@ import {MapFileReaderVS} from '../lib/mapfiles/map-file-vs.js';
describe('Map setup', () => {
it('VS-map preferred load address', () => {
const reader = new MapFileReaderVS('');
expect(reader.preferredLoadAddress).toEqual(0x400000, 'default load address');
expect(reader.preferredLoadAddress).toEqual(0x400000);
reader.tryReadingPreferredAddress(' Preferred load address is 00400000');
expect(reader.preferredLoadAddress).toEqual(0x400000);
@@ -239,12 +239,12 @@ describe('VS-Map load test', () => {
expect(reader.segments.length).toEqual(1);
expect(unwrap(reader.getSegmentInfoByUnitName('ConsoleApplication1.obj')).addressInt).toEqual(0x411000);
expect(reader.getSegmentOffset('0001')).toEqual(0x401000, 'offset 1');
expect(reader.getSegmentOffset('0002')).toEqual(0x411000, 'offset 2');
expect(reader.getSegmentOffset('0003')).toEqual(0x416000, 'offset 3');
expect(reader.getSegmentOffset('0004')).toEqual(0x419000, 'offset 4');
expect(reader.getSegmentOffset('0005')).toEqual(0x41a000, 'offset 5');
expect(reader.getSegmentOffset('0007')).toEqual(0x41c000, 'offset 7');
expect(reader.getSegmentOffset('0001')).toEqual(0x401000);
expect(reader.getSegmentOffset('0002')).toEqual(0x411000);
expect(reader.getSegmentOffset('0003')).toEqual(0x416000);
expect(reader.getSegmentOffset('0004')).toEqual(0x419000);
expect(reader.getSegmentOffset('0005')).toEqual(0x41a000);
expect(reader.getSegmentOffset('0007')).toEqual(0x41c000);
});
});
+1 -1
View File
@@ -432,7 +432,7 @@ describe('Pascal', () => {
lang: languages.pascal.id,
};
compiler = new FPCCompiler(info, ce);
compiler = new FPCCompiler(info as unknown as any, ce);
});
it('Original behaviour (old unitname)', async () => {
+2 -1
View File
@@ -24,12 +24,13 @@
import {describe, expect, it} from 'vitest';
import {MapFileReader} from '../lib/mapfiles/map-file.js';
import {PELabelReconstructor} from '../lib/pe32-support.js';
describe('Basic reconstructions', () => {
it('No lines', () => {
const lines = [];
const reconstructor = new PELabelReconstructor(lines, false, false);
const reconstructor = new PELabelReconstructor(lines, false, new MapFileReader('unused'), false);
expect(reconstructor.asmLines.length).toEqual(0);
});
});
+23 -22
View File
@@ -28,6 +28,7 @@ import {DynamoDB, GetItemCommand, PutItemCommand, QueryCommand, UpdateItemComman
import {GetObjectCommand, PutObjectCommand, S3} from '@aws-sdk/client-s3';
import {sdkStreamMixin} from '@smithy/util-stream';
import {mockClient} from 'aws-sdk-client-mock';
import {beforeEach, describe, expect, it} from 'vitest';
import * as properties from '../../lib/properties.js';
import {StorageS3} from '../../lib/storage/index.js';
@@ -47,16 +48,16 @@ describe('Find unique subhash tests', () => {
storagePrefix: 'prefix',
storageDynamoTable: 'table',
});
it('works when empty', () => {
it('works when empty', async () => {
const storage = new StorageS3(httpRootDir, compilerProps, awsProps);
mockDynamoDb.on(QueryCommand, {TableName: 'table'}).resolves({});
return storage.findUniqueSubhash('ABCDEFGHIJKLMNOPQRSTUV').should.eventually.deep.equal({
await expect(storage.findUniqueSubhash('ABCDEFGHIJKLMNOPQRSTUV')).resolves.toEqual({
alreadyPresent: false,
prefix: 'ABCDEF',
uniqueSubHash: 'ABCDEFGHI',
});
});
it('works when not empty', () => {
it('works when not empty', async () => {
const storage = new StorageS3(httpRootDir, compilerProps, awsProps);
mockDynamoDb.on(QueryCommand, {TableName: 'table'}).resolves({
Items: [
@@ -67,13 +68,13 @@ describe('Find unique subhash tests', () => {
],
});
return storage.findUniqueSubhash('ABCDEFGHIJKLMNOPQRSTUV').should.eventually.deep.equal({
await expect(storage.findUniqueSubhash('ABCDEFGHIJKLMNOPQRSTUV')).resolves.toEqual({
alreadyPresent: false,
prefix: 'ABCDEF',
uniqueSubHash: 'ABCDEFGHI',
});
});
it("works when there's a collision", () => {
it("works when there's a collision", async () => {
const storage = new StorageS3(httpRootDir, compilerProps, awsProps);
mockDynamoDb.on(QueryCommand, {TableName: 'table'}).resolves({
Items: [
@@ -83,13 +84,13 @@ describe('Find unique subhash tests', () => {
},
],
});
return storage.findUniqueSubhash('ABCDEFGHIJKLMNOPQRSTUV').should.eventually.deep.equal({
await expect(storage.findUniqueSubhash('ABCDEFGHIJKLMNOPQRSTUV')).resolves.toEqual({
alreadyPresent: false,
prefix: 'ABCDEF',
uniqueSubHash: 'ABCDEFGHIJ',
});
});
it('finds an existing match', () => {
it('finds an existing match', async () => {
const storage = new StorageS3(httpRootDir, compilerProps, awsProps);
mockDynamoDb.on(QueryCommand, {TableName: 'table'}).resolves({
Items: [
@@ -99,7 +100,7 @@ describe('Find unique subhash tests', () => {
},
],
});
return storage.findUniqueSubhash('ABCDEFGHIJKLMNOPQRSTUV').should.eventually.deep.equal({
await expect(storage.findUniqueSubhash('ABCDEFGHIJKLMNOPQRSTUV')).resolves.toEqual({
alreadyPresent: true,
prefix: 'ABCDEF',
uniqueSubHash: 'ABCDEFGHI',
@@ -131,15 +132,15 @@ describe('Stores to s3', () => {
config: 'yo',
};
await storage.storeItem(object, {get: () => 'localhost'});
mockS3
.commandCalls(PutObjectCommand, {
expect(
mockS3.commandCalls(PutObjectCommand, {
Bucket: 'bucket',
Key: 'prefix/ABCDEFGHIJKLMNOP',
Body: 'yo',
})
.should.have.lengthOf(1);
mockDynamoDb
.commandCalls(PutItemCommand, {
}),
).toHaveLength(1);
expect(
mockDynamoDb.commandCalls(PutItemCommand, {
TableName: 'table',
Item: {
prefix: {S: 'ABCDEF'},
@@ -148,8 +149,8 @@ describe('Stores to s3', () => {
stats: {M: {clicks: {N: '0'}}},
creation_ip: {S: 'localhost'},
},
})
.should.have.lengthOf(1);
}),
).toHaveLength(1);
});
});
@@ -190,12 +191,12 @@ describe('Retrieves from s3', () => {
.resolves({Body: sdkStreamMixin(stream)});
const result = await storage.expandId('ABCDEF');
result.should.deep.equal({config: 'I am a monkey'});
expect(result).toEqual({config: 'I am a monkey'});
});
it('should handle failures', async () => {
const storage = new StorageS3(httpRootDir, compilerProps, awsProps);
mockDynamoDb.on(GetItemCommand).resolves({});
return storage.expandId('ABCDEF').should.be.rejectedWith(Error, 'ID ABCDEF not present in links table');
await expect(storage.expandId('ABCDEF')).rejects.toThrow('ID ABCDEF not present in links table');
});
});
@@ -217,8 +218,8 @@ describe('Updates counts in s3', async () => {
it('should increment for simple cases', async () => {
const storage = new StorageS3(httpRootDir, compilerProps, awsProps);
await storage.incrementViewCount('ABCDEF');
mockDynamoDb
.commandCalls(UpdateItemCommand, {
expect(
mockDynamoDb.commandCalls(UpdateItemCommand, {
ExpressionAttributeValues: {':inc': {N: '1'}},
Key: {
prefix: {S: 'ABCDEF'},
@@ -227,7 +228,7 @@ describe('Updates counts in s3', async () => {
ReturnValues: 'NONE',
TableName: 'table',
UpdateExpression: 'SET stats.clicks = stats.clicks + :inc',
})
.should.have.lengthOf(1);
}),
).toHaveLength(1);
});
});
+7 -6
View File
@@ -22,8 +22,9 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import {describe, expect, it} from 'vitest';
import {StorageBase} from '../../lib/storage/index.js';
import {should} from '../utils.js';
describe('Hash tests', () => {
// afterEach(() => restore());
@@ -31,14 +32,14 @@ describe('Hash tests', () => {
for (let i = 0; i < 256; ++i) {
const buf = Buffer.of(i);
const as64 = StorageBase.encodeBuffer(buf);
as64.should.not.contain('/');
as64.should.not.contain('+');
expect(as64).not.toContain('/');
expect(as64).not.toContain('+');
}
});
const badResult = 'R0Buttabcdefghio1327698asdhjkJJklQp'.toLowerCase(); // Butt hash, see https://github.com/compiler-explorer/compiler-explorer/issues/1297
it('should detect profanities in hashes', () => {
StorageBase.isCleanText('I am the very model of a major general').should.be.true;
StorageBase.isCleanText(badResult).should.be.false;
expect(StorageBase.isCleanText('I am the very model of a major general')).toBe(true);
expect(StorageBase.isCleanText(badResult)).toBe(false);
});
// it('should avoid profanities and illegible characters in hashes', () => {
// const testCase = {some: 'test'};
@@ -62,6 +63,6 @@ describe('Hash tests', () => {
const testCase = {some: 'test'};
const {config} = StorageBase.getSafeHash(testCase);
const asObj = JSON.parse(config);
should.not.exist(asObj.nonce);
expect(asObj).not.toHaveProperty('nonce');
});
});
+1 -1
View File
@@ -35,7 +35,7 @@ import {CompilationQueue} from '../lib/compilation-queue.js';
import {CompilerProps, fakeProps} from '../lib/properties.js';
import {CompilerInfo} from '../types/compiler.interfaces.js';
import {ParseFiltersAndOutputOptions} from '../types/features/filters.interfaces.js';
import {Language} from '../types/languages.interfaces';
import {Language} from '../types/languages.interfaces.js';
// TODO: Find proper type for options
export function makeCompilationEnvironment(options: Record<string, any>): CompilationEnvironment {