Skip to content

Commit 7c2d0b1

Browse files
committed
submodule and coverage support
1 parent a19038d commit 7c2d0b1

File tree

6 files changed

+113
-92
lines changed

6 files changed

+113
-92
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Some extra optional settings:
5050
- `events:event:ref_include` - same as `ref_ignore`, but a pass list instead of block list.
5151
- `kill_children` - if present and true, `tree-kill` is used to kill the child processes, required
5252
if shell/batch script forks test process (e.g. a batch script calls python).
53+
- `repos` - an array of submodules or map of modules to their corresponding paths.
5354

5455
Finally, ensure these scripts are executable by node:
5556
```

runAllTests.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function runAllTests(id, repo, logDir)
1212
try
1313
%% Initialize enviroment
1414
dbPath = fullfile(logDir, '.db.json'); % TODO Load from config file
15+
[~, repo] = fileparts(repo); % Ensure not full path
1516
fprintf('Running tests\n')
1617
fprintf('Repo = %s, sha = %s\n', repo, id)
1718
origDir = pwd;
@@ -30,7 +31,7 @@ function runAllTests(id, repo, logDir)
3031
main_tests = testsuite('IncludeSubfolders', true);
3132

3233
%% Gather signals tests
33-
root = getOr(dat.paths,'rigbox');
34+
root = getOr(dat.paths, 'rigbox');
3435
signals_tests = testsuite(fullfile(root, 'signals', 'tests'), ...
3536
'IncludeSubfolders', true);
3637

@@ -44,12 +45,14 @@ function runAllTests(id, repo, logDir)
4445
% the sortByFixtures method to sort the suite.
4546
all_tests = [main_tests signals_tests alyx_tests];
4647
% If the repo under test is alyx, filter out irrelevent tests
47-
if endsWith(repo, 'alyx')
48+
if strcmp(repo, 'alyx')
4849
all_tests = all_tests(startsWith({all_tests.Name}, 'Alyx', 'IgnoreCase', true));
49-
elseif endsWith(repo, 'alyx-matlab')
50+
elseif strcmp(repo, 'alyx-matlab')
5051
all_tests = alyx_tests;
51-
elseif endsWith(repo, 'signals')
52+
root = fullfile(root, repo);
53+
elseif strcmp(repo, 'signals')
5254
all_tests = signals_tests;
55+
root = fullfile(root, repo);
5356
end
5457

5558
% Filter out performance tests

serve.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,10 @@ function checkout(repoPath, ref) {
350350
function listSubmodules(repoPath) {
351351
if (!shell.which('git')) { throw new Error('Git not found on path'); }
352352
shell.pushd(repoPath);
353-
let listModules = 'git config --file .gitmodules --get-regexp path | awk \'{ print $2 }\'';
354-
const modules = shell.exec(listModules);
353+
let listModules = 'git config --file .gitmodules --get-regexp path';
354+
const modules = shell.exec(listModules)
355355
shell.popd();
356-
return (!modules.code && modules.stdout !== '')? modules.split('\n') : null;
356+
return (!modules.code && modules.stdout !== '')? modules.match(/(?<=submodule.)[\w-]+/g) : null;
357357
}
358358

359359
/**
@@ -366,14 +366,14 @@ function listSubmodules(repoPath) {
366366
*/
367367
function getRepoPath(name) {
368368
if (!config.repos) { return process.env['REPO_PATH']; } // Legacy, to remove
369-
if (config.repos.name) { return config.repos.name; } // Found path, return
370-
for (let repo of config.repos) {
371-
let modules = listSubmodules(repo);
372-
if (modules && modules.includes(name)) {
373-
// If the repo is a submodule, modify path
374-
return repo + path.sep + name;
375-
}
369+
if (config.repos[name]) { return config.repos[name]; } // Found path, return
370+
const modules = listSubmodules(process.env['REPO_PATH']);
371+
let repoPath = process.env['REPO_PATH'];
372+
if (modules && modules.includes(name)) {
373+
// If the repo is a submodule, modify path
374+
repoPath += (path.sep + name);
376375
}
376+
return repoPath; // No modules matched, return default
377377
}
378378

379379

@@ -578,5 +578,6 @@ queue.on('finish', (err, job) => { // On job end post result to API
578578
});
579579

580580
module.exports = {
581-
updateStatus, srv, handler, setAccessToken, prepareEnv, runTests, eventCallback
581+
updateStatus, srv, handler, setAccessToken, prepareEnv,
582+
runTests, eventCallback, getRepoPath, listSubmodules
582583
}

test/coverage.test.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@ const fs = require('fs');
22
const assert = require('assert');
33
const path = require('path');
44
const sinon = require('sinon');
5+
const expect = require('chai').expect;
56

67
const config = require('../config/config').settings;
78
const Coverage = require('../coverage');
89

910
const dummy_id = '1c33a6e2ac7d7fc098105b21a702e104e09767cf';
1011

1112

12-
xdescribe('Test coverage parser:', function() {
13+
describe('Test coverage parser:', function() {
1314
var testable;
15+
var sandbox;
1416
// Check NODE_ENV is correctly set, meaning our imported settings will be test ones
15-
before(function () {
16-
assert(process.env.NODE_ENV.startsWith('test'), 'Test run outside test env')
17+
beforeEach(function () {
18+
let md5 = '385a5d56850127317c317b0f66e91078';
19+
let code = 'line1\nline2\n\rline3\n\rline4';
1720
testable = function(obj, done) {
18-
assert(obj.source_files);
21+
expect([291, 63]).to.include(obj.source_files.length);
22+
let file = obj.source_files[0];
23+
expect(file).to.have.all.keys('name', 'source_digest', 'coverage');
24+
expect(file['source_digest']).to.eq(md5);
1925
done();
2026
};
27+
sandbox = sinon.createSandbox();
28+
sandbox
29+
.stub(fs, 'readFileSync')
30+
.withArgs(sinon.match((x) => x.replace('\\', '/').startsWith('C:/Rigbox')))
31+
.returns(code)
32+
.withArgs(sinon.match((x) => x.replace('\\', '/').startsWith('C:/ibllib')))
33+
.returns(code);
34+
fs.readFileSync.callThrough();
2135
})
2236

2337
it('Check loading MATLAB', function (done) {
@@ -27,8 +41,10 @@ xdescribe('Test coverage parser:', function() {
2741

2842
it('Check loading Python', function (done) {
2943
let xmlPath = path.resolve('test', 'fixtures', 'CoverageResults.py.xml')
30-
Coverage(xmlPath, '', dummy_id, obj => testable(obj, done) );
44+
Coverage(xmlPath, 'ibllib', dummy_id, obj => testable(obj, done) );
3145
});
46+
47+
afterEach(function () { sandbox.restore(); });
3248
});
3349

3450

test/fixtures/CoverageResults.mat.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
timestamp="1603119812.882"
77
version="">
88
<sources>
9-
<source>C:\Users\Experiment\Documents\GitHub\Rigbox\</source>
9+
<source>C:\Rigbox\</source>
1010
</sources>
1111
<packages>
1212
<package branch-rate="NaN" complexity="NaN" line-rate="0.31707" name="">
@@ -51801,4 +51801,4 @@
5180151801
</classes>
5180251802
</package>
5180351803
</packages>
51804-
</coverage>
51804+
</coverage>

0 commit comments

Comments
 (0)