Skip to content

Commit

Permalink
Merge pull request #54 from neelabhg/fix_28_gcc_output_parse_error
Browse files Browse the repository at this point in the history
Fix 28 gcc output parse error
  • Loading branch information
neelabhg committed Nov 26, 2014
2 parents 1a56473 + b4db1b6 commit 9688029
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
38 changes: 19 additions & 19 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ <h3 id="man-pages-search-title">Search Linux Man Pages</h3>
<p>Compiler:
<span data-bind="text: compileStatus, css: compileStatusClass, visible: !showErrorWarningLabel()">Idle</span>
<a href="#"
data-bind="text: errorWarningLabel, visible: showErrorWarningLabel, css: compileStatusClass, attr: {'data-content': '<pre>' + lastGccOutput() + '</pre>'}"
tabindex="0" data-toggle="modal" data-target="#gccErrorWindow" data-html="true" data-placement="auto top" data-trigger="focus"></a>
data-bind="text: errorWarningLabel, visible: showErrorWarningLabel, css: compileStatusClass"
data-toggle="modal" data-target="#gccErrorWindow"></a>
</p>
</div>
</div>
Expand All @@ -275,28 +275,28 @@ <h3 id="man-pages-search-title">Search Linux Man Pages</h3>
<p class="text-muted pull-right"><small>&copy; 2014, <a target="_blank" href="https://github.com/angrave">Lawrence Angrave</a> and <a target="_blank" href="http://neelabhgupta.com/">Neelabh Gupta</a></small></p>
</div>
</div>


</div>
</div>
</div><!--/.show-if-supported -->
<!-- Modal -->
<div class="modal fade" id="gccErrorWindow" tabindex="-1" role="dialog" aria-labelledby="gccErrorLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="gccErrorLabel" data-bind="text: errorWarningLabel"></h4>
</div>
<div class="modal-body">
<pre data-bind="text: lastGccOutput()"></pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>

<!-- GCC Error Modal -->
<div class="modal fade" id="gccErrorWindow" tabindex="-1" role="dialog" aria-labelledby="gccErrorLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="gccErrorLabel" data-bind="text: errorWarningLabel"></h4>
</div>
<div class="modal-body">
<pre data-bind="text: lastGccOutput()"></pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div><!--/.show-if-supported -->

<!-- ==================== Javascript ==================== -->

<!-- build:js scripts/vendor.js -->
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/gcc-output-parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
window.GccOutputParser = (function () {
'use strict';

var gccOutputParseRe = /(program\.c|gcc|cc1|collect2):\s*(.+)\s*:\s*(.+)\s*/;
var gccOutputParseRe = /(.+?):\s*(.+)\s*:\s*(.+)\s*/;
var gccRowColTypeParseRe = /(\d+):(\d+):\s*(.+)/;
var gccOutputTypeTextSplitRe = /\s*(.+)\s*:\s*(.+)\s*/;
var errorTypeMap = {
Expand Down
6 changes: 6 additions & 0 deletions app/scripts/sys-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ window.SysRuntime = (function () {
aceAnnotationType = 'info';
}

if (typeof error.type === 'undefined') {
// if the errors are not in program.c, invalidate the row and column so that
// the editor does not place an annotation
error.row = error.col = -1;
}

return {
// line numbers in ace start from zero
row: error.row - 1,
Expand Down
9 changes: 8 additions & 1 deletion app/scripts/sys-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ window.SysViewModel = (function () {

str += errors ? (errors + ' error' + (errors > 1 ? 's ' : ' ')) : '';
str += warnings ? (warnings + ' warning' + (warnings > 1 ? 's' : '')) : '';
if(str) { str += '\u2026'; }
if (str) {
str += '\u2026';
} else {
if (self.showErrorWarningLabel()) {
// the compilation failed but error/warning count is not available
str = self.compileStatus() + '\u2026';
}
}
return str;
});
self.showErrorWarningLabel = ko.pureComputed(function () {
Expand Down
19 changes: 15 additions & 4 deletions test/spec/gcc-output-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,28 @@
// linker error
describe('when given a linker error string', function () {
beforeEach(function () {
var compilerOutput = 'libcygwin.a(libcmain.o): In function \'main\':\n' +
'libcmain.c:39: undefined reference to \'WinMain\'\n' +
'collect2: error: ld returned 1 exit status';
var compilerOutput = '/tmp/ccwIU8df.o: In function \'main\':\n' +
'program.c:(.text+0x20): undefined reference to \'nonExistentFunction\'\n' +
'collect2: error: ld returned 1 exit status';
this.results = this.parser.parse(compilerOutput);
});

it('should return the correct error information', function () {
assert.typeOf(this.results, 'Array');
assert.lengthOf(this.results, 1); // one error
assert.lengthOf(this.results, 2); // two errors

// error one
var error = this.results[0];
assert.propertyVal(error, 'column', 0);
// TODO: currently the gccErrorType returned is incorrect, so the assertion is commented out
//assert.propertyVal(error, 'gccErrorType', 'error');
assert.propertyVal(error, 'row', 0);
assert.propertyVal(error, 'text', 'undefined reference to \'nonExistentFunction\'');
assert.propertyVal(error, 'type', 'compile');

// error two
error = this.results[1];
assert.propertyVal(error, 'column', 0);
assert.propertyVal(error, 'gccErrorType', 'error');
assert.propertyVal(error, 'row', 0);
assert.propertyVal(error, 'text', 'ld returned 1 exit status');
Expand Down

0 comments on commit 9688029

Please sign in to comment.