Skip to content

Commit

Permalink
Merge branch '0.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
gutomaia committed Apr 17, 2014
2 parents 9f05c1f + 871d7d0 commit 652f605
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 40 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ default: test
endif

.git/hooks/pre-commit:
@echo "Instaling pre-commit hook: \c"
@cp hooks/pre-commit .git/hooks/pre-commit
@touch $@
${CHECK}

node_modules: .git/hooks/pre-commit package.json
@echo "NPM installing packages: \c"
Expand Down Expand Up @@ -301,6 +303,7 @@ clean:
purge: clean
@rm -rf node_modules
@rm -rf deps
@rm .git/hooks/pre-commit

run: node_modules download_deps
@./node_modules/.bin/supervisor ./app.js
Expand Down
7 changes: 2 additions & 5 deletions bin/nodenes
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/usr/bin/env node
// -*- js -*-

global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");

var compiler = require("../lib/compiler.js");

var sys = require('util');

//var nodenes = require("../nodenes");

var options = {
copyright:true,
Expand All @@ -21,7 +18,7 @@ var filename = null;

if (args.length === 0){
console.log('Usage');
//process.exit(1);
process.exit(1);
}

while(args.length > 0){
Expand Down Expand Up @@ -51,7 +48,7 @@ while(args.length > 0){


if (options.copyright){
sys.print('nodeNES by Guto Maia');
sys.print('nodeNES by Guto Maia\n');
}

if (options.verbose) {
Expand Down
21 changes: 20 additions & 1 deletion hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
#!/bin/sh

BASEDIR="$(dirname $0)/../.."

if git diff-index --quiet HEAD --; then

echo "1"

cd $BASEDIR && make test
RESULT=$?

else

git stash -q --keep-index -u
cd $BASEDIR && make test
RESULT=$?
git stash pop -q

echo "2"

fi

[ $RESULT -ne 0 ] && exit 1
exit 0
9 changes: 1 addition & 8 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ define([
return look_ahead(tokens, index, 'T_MARKER');
}

function t_address_or_t_binary_number(tokens, index) {
return OR([t_address, t_binary_number], tokens, index);
}

function t_address_or_t_binary_number_or_t_decimal_argument(tokens, index) {
return OR([t_address, t_binary_number, t_decimal_argument], tokens, index);
}
Expand Down Expand Up @@ -309,11 +305,8 @@ define([
return labels[token.value];
} else if (token.type === 'T_STRING'){
return token.value.substr(1, token.value.length - 2);
} else {
console.log("Could not get that value");
console.log(token);
throw "Could not get that value";
}
throw "Could not get that value";
}

compiler.prototype.path = '';
Expand Down
32 changes: 6 additions & 26 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ util.prototype.init_fs = function () {

util.prototype.on_write_end = function (filename, url){};

util.prototype.on_error = function (e){};

util.prototype.write_file_with_browser_fileapi =function (filename, data){
if (this.fs === undefined){
this.filename = filename;
Expand All @@ -78,40 +80,18 @@ util.prototype.write_file_with_browser_fileapi =function (filename, data){
instance.on_write_end(filename, fileEntry.toURL());
};
fileWriter.onerror = function(e) {
//add_status_msg('File', '<a href="' + fileEntry.toURL() + '">Download</a>', 'warning');
console.log(e);
instance.on_error(e);
};
fileWriter.write(new Blob([uint], {type:"application/octet-stream"}));
}, this.errorHandler);
}, this.errorHandler);
}, errorFileHandler);
}, errorFileHandler);
}
};

var instance = new util();

function errorFileHandler (e) {
var msg = '';
switch (e.code) {
case FileError.QUOTA_EXCEEDED_ERR:
msg = 'QUOTA_EXCEEDED_ERR';
break;
case FileError.NOT_FOUND_ERR:
msg = 'NOT_FOUND_ERR';
break;
case FileError.SECURITY_ERR:
msg = 'SECURITY_ERR';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'INVALID_MODIFICATION_ERR';
break;
case FileError.INVALID_STATE_ERR:
msg = 'INVALID_STATE_ERR';
break;
default:
msg = 'Unknown Error';
break;
}
console.log('Error: ' + msg);
instance.on_error(e);
}


Expand Down
33 changes: 33 additions & 0 deletions tests/utils_requestfilesystem_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var fs = require('fs');
var sinon = require('sinon');
var utils = require('../lib/utils.js');


var BlobImpl = function (byteArray, options){
this.byteArray = byteArray;
};
Expand Down Expand Up @@ -102,4 +103,36 @@ exports.test_open_file_with_request_file_system = function(test){
var hl = fs.readFileSync(filename, 'binary');
test.equal('world', hl);
test.done();
};

exports.test_write_file_with_write_error = function(test){
var have_erros = false;

utils.on_error = function (e){
have_erros = true;
};

var st = sinon.stub(fs, 'writeFileSync');
st.onFirstCall().throws("Error");

utils.write_file(this.filename, 'error');

test.ok(have_erros);
test.done();
};

exports.test_on_get_file_call_error_callback = function(test){
var have_erros = false;

utils.on_error = function (e){
have_erros = true;
};

var before = FileNode.prototype.createWriter;
FileNode.prototype.createWriter = function (){throw "error";};
utils.write_file(this.filename, 'error');
FileNode.prototype.createWriter = before;

test.ok(have_erros);
test.done();
};

0 comments on commit 652f605

Please sign in to comment.