Skip to content

Commit 1b7fe24

Browse files
authored
Perform some general maintenance on the test suite (compiler-explorer#1840)
1 parent 7ce90a3 commit 1b7fe24

21 files changed

+492
-438
lines changed

Diff for: lib/logger.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ exports.logToPapertrail = (host, port, identifier) => {
100100
};
101101

102102
exports.suppressConsoleLog = () => {
103-
logger.remove(consoleTransportInstance);
103+
consoleTransportInstance.silent = true;
104104
};
105105

106106
exports.logger = logger;

Diff for: test/_setup.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const logger = require('../lib/logger');
2+
3+
// this hook will run once before any tests are executed
4+
before(() => {
5+
logger.suppressConsoleLog();
6+
});

Diff for: test/analysis-tests.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ const languages = {
3131
analysis: {id: 'analysis'}
3232
};
3333

34-
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
35-
3634
describe('LLVM-mca tool definition', () => {
37-
const ce = new CompilationEnvironment(compilerProps);
38-
const info = {
39-
exe: null,
40-
remote: true,
41-
lang: languages.analysis.id
42-
};
43-
const a = new LLVMmcaTool(info, ce);
35+
let ce, a;
36+
37+
before(() => {
38+
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
39+
ce = new CompilationEnvironment(compilerProps);
40+
const info = {
41+
exe: null,
42+
remote: true,
43+
lang: languages.analysis.id
44+
};
45+
a = new LLVMmcaTool(info, ce);
46+
});
4447

4548
it('should have most filters disabled', () => {
4649
a.compiler.disabledFilters.should.be.deep.equal(['labels', 'directives', 'commentOnly', 'trim']);

Diff for: test/base-compiler-tests.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ const languages = {
4242
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
4343

4444
describe('Basic compiler invariants', function () {
45-
const ce = new CompilationEnvironment(compilerProps);
45+
let ce, compiler;
4646
const info = {
4747
exe: null,
4848
remote: true,
4949
lang: languages['c++'].id,
5050
ldPath: []
5151
};
5252

53-
const compiler = new BaseCompiler(info, ce);
53+
before(() => {
54+
ce = new CompilationEnvironment(compilerProps);
55+
compiler = new BaseCompiler(info, ce);
56+
});
5457

5558
it('should recognize when optOutput has been request', () => {
5659
compiler.optOutputRequested(["please", "recognize", "-fsave-optimization-record"]).should.equal(true);
@@ -90,17 +93,20 @@ describe('Basic compiler invariants', function () {
9093
});
9194

9295
describe('Compiler execution', function () {
93-
const ce = new CompilationEnvironment(compilerProps);
96+
let ce, compiler;
9497
const info = {
9598
exe: null,
9699
remote: true,
97100
lang: languages['c++'].id,
98101
ldPath: []
99102
};
100103

101-
afterEach(() => sinon.restore());
104+
before(() => {
105+
ce = new CompilationEnvironment(compilerProps);
106+
compiler = new BaseCompiler(info, ce);
107+
});
102108

103-
const compiler = new BaseCompiler(info, ce);
109+
afterEach(() => sinon.restore());
104110

105111
function stubOutCallToExec(execStub, compiler, content, result, nthCall) {
106112
execStub.onCall(nthCall || 0).callsFake((compiler, args, options) => {

Diff for: test/cache-tests.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function basicTests(factory) {
7171

7272
it('should store and retrieve binary buffers', () => {
7373
const cache = factory();
74-
const buffer = Buffer.alloc(2 * 1024 * 1024);
74+
const buffer = Buffer.alloc(2 * 1024);
7575
buffer.fill('@');
7676
return cache.put('a key', buffer, 'bob')
7777
.then(() => {
@@ -160,9 +160,9 @@ describe('On disk caches', () => {
160160
return cache.put('a key', 'a value', 'bob')
161161
.then(() => {
162162
const promises = [];
163-
const oneK = "".padEnd(1024);
164-
for (let i = 0; i < 1024; i++) {
165-
promises.push(cache.put(`key${i}`, oneK));
163+
const oneHundredK = "".padEnd(1024 * 100);
164+
for (let i = 0; i < 12; i++) {
165+
promises.push(cache.put(`key${i}`, oneHundredK));
166166
}
167167
return Promise.all(promises);
168168
})

Diff for: test/compilation-env.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ const props = {
3636
cacheConfig: 'InMemory(10)'
3737
};
3838

39-
const compilerProps = new properties.CompilerProps({}, properties.fakeProps(props));
40-
4139
describe('Compilation environment', () => {
40+
let compilerProps;
41+
42+
before(() => {
43+
compilerProps = new properties.CompilerProps({}, properties.fakeProps(props));
44+
});
45+
4246
it('Should cache by default', () => {
4347
const ce = new CompilationEnvironment(compilerProps);
4448
return ce.cacheGet('foo').should.eventually.equal(null)

Diff for: test/compiler-finder-tests.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ const props = {
4040
compilers: "goodCompiler:&badCompiler"
4141
};
4242

43-
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps(props));
44-
4543
describe('Compiler-finder', function () {
44+
let compilerProps;
45+
46+
before(() => {
47+
compilerProps = new properties.CompilerProps(languages, properties.fakeProps(props));
48+
});
49+
4650
it('should not hang for undefined groups (Bug #860)', () => {
4751
const optionsHandler = {
4852
get: () => {

Diff for: test/compilers/argument-parsers-tests.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ const languages = {
3636
'c++': {id: 'c++'}
3737
};
3838

39-
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
39+
let env;
4040

4141
function makeCompiler(stdout, stderr, code) {
42+
if (env === undefined) {
43+
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
44+
env = new CompilationEnvironment(compilerProps);
45+
}
46+
4247
if (code === undefined) code = 0;
43-
const env = new CompilationEnvironment(compilerProps);
4448
const compiler = new FakeCompiler({lang: languages['c++'].id, remote: true}, env);
4549
compiler.exec = () => Promise.resolve({code: code, stdout: stdout || "", stderr: stderr || ""});
4650
compiler.execCompilerCached = compiler.exec;
@@ -155,7 +159,11 @@ describe('pascal parser', () => {
155159
});
156160

157161
describe('popular compiler arguments', () => {
158-
let compiler = makeCompiler("-fsave-optimization-record\n-x\n-g\n-fcolor-diagnostics\n-O<number> optimization level\n-std=<c++11,c++14,c++17z>");
162+
let compiler;
163+
164+
before(() => {
165+
compiler = makeCompiler("-fsave-optimization-record\n-x\n-g\n-fcolor-diagnostics\n-O<number> optimization level\n-std=<c++11,c++14,c++17z>");
166+
});
159167

160168
it('should return 5 arguments', () => {
161169
return parsers.Clang.parse(compiler).then(compiler => {

Diff for: test/d-tests.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,19 @@ const languages = {
3636
d: {id: 'd'}
3737
};
3838

39-
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
40-
4139
describe('D', () => {
42-
const ce = new CompilationEnvironment(compilerProps);
40+
let ce;
4341
const info = {
4442
exe: null,
4543
remote: true,
4644
lang: languages.d.id
4745
};
4846

47+
before(() => {
48+
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
49+
ce = new CompilationEnvironment(compilerProps);
50+
});
51+
4952
it('LDC should not allow -run parameter', () => {
5053
const compiler = new LDCCompiler(info, ce);
5154
compiler.filterUserOptions(["hello", "-run", "--something"]).should.deep.equal(["hello", "--something"]);

Diff for: test/filter-tests.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ function processAsm(filename, filters) {
3838
return parser.process(file, filters);
3939
}
4040

41-
const cases = fs.readdirSync(__dirname + '/cases')
41+
const filesInCaseDir = fs.readdirSync(__dirname + '/cases')
42+
.map(function (x) {
43+
return 'cases/' + x;
44+
});
45+
46+
const cases = filesInCaseDir
4247
.filter(function (x) {
4348
return x.match(/\.asm$/);
44-
})
45-
.map(function (x) {
46-
return __dirname + '/cases/' + x;
4749
});
4850

4951
function bless(filename, output, filters) {
@@ -58,24 +60,24 @@ function dump(file) {
5860
}
5961

6062
function testFilter(filename, suffix, filters) {
61-
const result = processAsm(filename, filters);
62-
6363
const expected = filename + suffix;
64-
let json = false;
64+
const json = filesInCaseDir.includes(expected + '.json');
65+
6566
let file;
66-
try {
67-
file = fs.readFileSync(expected + '.json', 'utf-8');
68-
json = true;
69-
} catch (e) {
67+
68+
if (json) {
69+
file = fs.readFileSync(__dirname + '/' + expected + '.json', 'utf-8');
7070
}
71-
if (!file) {
72-
try {
73-
file = fs.readFileSync(expected, 'utf-8');
74-
} catch (e) {
75-
return;
76-
}
71+
else if (filesInCaseDir.includes(expected)) {
72+
file = fs.readFileSync(__dirname + '/' + expected, 'utf-8');
73+
}
74+
else {
75+
return;
7776
}
78-
it(filename, function () {
77+
78+
it(filename, () => {
79+
const result = processAsm(__dirname + '/' + filename, filters);
80+
7981
if (json) {
8082
file = JSON.parse(file);
8183
} else {

Diff for: test/golang-tests.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ const languages = {
3636
go: {id: 'go'}
3737
};
3838

39-
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
40-
41-
const ce = new CompilationEnvironment(compilerProps);
39+
let ce;
4240
const info = {
4341
exe: null,
4442
remote: true,
@@ -71,6 +69,11 @@ function testGoAsm(basefilename) {
7169
}
7270

7371
describe('GO asm tests', () => {
72+
before(() => {
73+
const compilerProps = new properties.CompilerProps(languages, properties.fakeProps({}));
74+
ce = new CompilationEnvironment(compilerProps);
75+
});
76+
7477
it('Handles unknown line number correctly', () => {
7578
return testGoAsm("test/golang/bug-901");
7679
});

Diff for: test/handlers/api-tests.js

+48-42
Original file line numberDiff line numberDiff line change
@@ -46,54 +46,60 @@ const languages = {
4646
extensions: ['.pas']
4747
}
4848
};
49+
const compilers = [
50+
{
51+
id: "gcc900",
52+
name: "GCC 9.0.0",
53+
lang: "c++"
54+
},
55+
{
56+
id: "fpc302",
57+
name: "FPC 3.0.2",
58+
lang: "pascal"
59+
},
60+
{
61+
id: "clangtrunk",
62+
name: "Clang trunk",
63+
lang: "c++"
64+
}
65+
];
4966

5067
chai.use(require("chai-http"));
5168
chai.should();
5269

5370
describe('API handling', () => {
54-
const app = express();
55-
const apiHandler = new ApiHandler({
56-
handle: res => {
57-
res.send("compile");
58-
},
59-
handlePopularArguments: res => {
60-
res.send("ok");
61-
},
62-
handleOptimizationArguments: res => {
63-
res.send("ok");
64-
}
65-
}, (key, def) => {
66-
switch (key) {
67-
case "formatters":
68-
return "formatt:badformatt";
69-
case "formatter.formatt.exe":
70-
return "echo";
71-
case "formatter.formatt.version":
72-
return "Release";
73-
case "formatter.formatt.name":
74-
return "FormatT";
75-
default:
76-
return def;
77-
}
71+
let app;
72+
73+
before(() => {
74+
app = express();
75+
const apiHandler = new ApiHandler({
76+
handle: res => {
77+
res.send("compile");
78+
},
79+
handlePopularArguments: res => {
80+
res.send("ok");
81+
},
82+
handleOptimizationArguments: res => {
83+
res.send("ok");
84+
}
85+
}, (key, def) => {
86+
switch (key) {
87+
case "formatters":
88+
return "formatt:badformatt";
89+
case "formatter.formatt.exe":
90+
return "echo";
91+
case "formatter.formatt.version":
92+
return "Release";
93+
case "formatter.formatt.name":
94+
return "FormatT";
95+
default:
96+
return def;
97+
}
98+
});
99+
app.use('/api', apiHandler.handle);
100+
apiHandler.setCompilers(compilers);
101+
apiHandler.setLanguages(languages);
78102
});
79-
app.use('/api', apiHandler.handle);
80-
const compilers = [{
81-
id: "gcc900",
82-
name: "GCC 9.0.0",
83-
lang: "c++"
84-
},
85-
{
86-
id: "fpc302",
87-
name: "FPC 3.0.2",
88-
lang: "pascal"
89-
},
90-
{
91-
id: "clangtrunk",
92-
name: "Clang trunk",
93-
lang: "c++"
94-
}];
95-
apiHandler.setCompilers(compilers);
96-
apiHandler.setLanguages(languages);
97103

98104
it('should respond to plain text compiler requests', () => {
99105
return chai.request(app)

0 commit comments

Comments
 (0)