[gjs] coverage: Don't error out on various files
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] coverage: Don't error out on various files
- Date: Wed, 27 Sep 2017 04:26:29 +0000 (UTC)
commit 2a1ed02bce5ae74bed099f3130a1aa30938894d2
Author: Philip Chimento <philip chimento gmail com>
Date: Fri Sep 22 22:52:49 2017 -0700
coverage: Don't error out on various files
The coverage statistics should handle files with #! on the first line,
and ignore files with names within angle brackets, which is our
convention for scripts that are fed to the JS engine programmatically.
https://bugzilla.gnome.org/show_bug.cgi?id=788166
installed-tests/js/testCoverage.js | 19 +++++++++++++++----
modules/_bootstrap/coverage.js | 6 ++++++
2 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/installed-tests/js/testCoverage.js b/installed-tests/js/testCoverage.js
index f0b4d39..8a0cbe6 100644
--- a/installed-tests/js/testCoverage.js
+++ b/installed-tests/js/testCoverage.js
@@ -1041,11 +1041,16 @@ describe('Coverage statistics container', function () {
"\n",
'uncached': "function f() {\n" +
" return 1;\n" +
- "}\n"
+ '}\n',
+ 'shebang': `#!/usr/bin/env gjs
+ function f() {}
+ `,
};
const MockFilenames = Object.keys(MockFiles).concat(['nonexistent']);
+ let container;
+
beforeEach(function () {
Coverage.getFileContents =
jasmine.createSpy('getFileContents').and.callFake(f => MockFiles[f]);
@@ -1053,11 +1058,10 @@ describe('Coverage statistics container', function () {
jasmine.createSpy('getFileChecksum').and.returnValue('abcd');
Coverage.getFileModificationTime =
jasmine.createSpy('getFileModificationTime').and.returnValue([1, 2]);
+ container = new Coverage.CoverageStatisticsContainer(MockFilenames);
});
it('fetches valid statistics for file', function () {
- let container = new Coverage.CoverageStatisticsContainer(MockFilenames);
-
let statistics = container.fetchStatistics('filename');
expect(statistics).toBeDefined();
@@ -1066,10 +1070,17 @@ describe('Coverage statistics container', function () {
});
it('throws for nonexisting file', function () {
- let container = new Coverage.CoverageStatisticsContainer(MockFilenames);
expect(() => container.fetchStatistics('nonexistent')).toThrow();
});
+ it('handles a shebang on line 1', function () {
+ expect(() => container.fetchStatistics('shebang')).not.toThrow();
+ });
+
+ it('ignores a file in angle brackets (our convention for programmatic scripts)', function () {
+ expect(() => container.fetchStatistics('<script>')).not.toThrow();
+ });
+
const MockCache = '{ \
"filename": { \
"mtime": [1, 2], \
diff --git a/modules/_bootstrap/coverage.js b/modules/_bootstrap/coverage.js
index 7bbde49..b7beae3 100644
--- a/modules/_bootstrap/coverage.js
+++ b/modules/_bootstrap/coverage.js
@@ -760,6 +760,9 @@ function _fetchCountersFromCache(filename, cache, nLines) {
}
function _fetchCountersFromReflection(filename, contents, nLines) {
+ // Shebang is illegal character sequence to JS parser
+ if (contents.startsWith('#!'))
+ contents = '//' + contents;
let reflection = Reflect.parse(contents);
let functions = functionsForAST(reflection);
@@ -798,6 +801,9 @@ function CoverageStatisticsContainer(prefixes, cache) {
}
function ensureStatisticsFor(filename) {
+ // Skip scripts fed to JS engine programmatically.
+ if (filename.startsWith('<') && filename.endsWith('>'))
+ return undefined;
if (!coveredFiles[filename])
coveredFiles[filename] = createStatisticsFor(filename);
return coveredFiles[filename];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]