Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 3, 2023
2 parents 1760613 + 163a540 commit b5e932b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
20 changes: 20 additions & 0 deletions src/eoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ program
.option('-b, --batch', 'Run in batch mode, suppress interactive messages')
.option('--no-color', 'Disable colorization of console messages')
.option('--track-optimization-steps', 'Save intermediate XMIR files')
.option('-c, --clean', 'Delete ./.eoc directory')
.option('--verbose', 'Print debug messages and full output of child processes');

program.command('audit')
Expand Down Expand Up @@ -89,6 +90,7 @@ program.command('register')
program.command('parse')
.description('Parse EO files into XMIR')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => parse(program.opts()));
Expand All @@ -100,6 +102,7 @@ program.command('parse')
program.command('assemble')
.description('Parse EO files into XMIR and join them with required dependencies')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()));
Expand All @@ -117,6 +120,7 @@ program.command('sodg')
.option('--include <names>', 'Generate SODG for these object names (using mask)', '**')
.option('--exclude <names>', 'Don\'t generate SODG for these objects')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
Expand All @@ -129,6 +133,7 @@ program.command('sodg')
program.command('transpile')
.description('Convert EO files into target language')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
Expand All @@ -141,6 +146,7 @@ program.command('transpile')
program.command('compile')
.description('Compile target language sources into binaries')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
Expand All @@ -154,6 +160,7 @@ program.command('compile')
program.command('link')
.description('Link together all binaries into a single executable binary')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
Expand All @@ -169,6 +176,7 @@ program.command('dataize')
.description('Run the single executable binary and dataize an object')
.option('--stack <size>', 'Change stack size', '1M')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
Expand All @@ -184,6 +192,7 @@ program.command('dataize')
program.command('test')
.description('Run all visible unit tests')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
Expand All @@ -203,3 +212,14 @@ try {
console.debug(e.stack);
process.exit(1);
}

/**
* Checks --clean option and clears the .eoc directory if true.
* @param {*} str Str
*/
function clear(str) {
if (program.opts().clean) {
clean({...program.opts(), ...str});
}
}

37 changes: 27 additions & 10 deletions test/commands/test_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ describe('compile', function() {
home = path.resolve('temp/test-compile/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(
path.resolve(home, 'src/simple.eo'),
[
'+package foo.bar',
'+alias org.eolang.io.stdout',
'',
'[args...] > app',
' stdout "Hello, world!" > @',
].join('\n')
);
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), simple());
const stdout = runSync([
'compile', '-s', path.resolve(home, 'src'), '-t', path.resolve(home, 'target'),
]);
Expand Down Expand Up @@ -89,4 +80,30 @@ describe('compile', function() {
);
done();
});

it('Cleans and compiles a simple .EO program', function(done) {
home = path.resolve('temp/test-compile/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), simple());
const stdout = runSync([
'compile', '--clean', '-s', path.resolve(home, 'src'), '-t', path.resolve(home, 'target'),
]);
assert(stdout.includes(`The directory ${path.resolve(home, 'target')} deleted`), stdout);
done();
});
});

/**
* Creates simple correct eo program.
* @return {string} simple eo program
*/
function simple() {
return [
'+package foo.bar',
'+alias org.eolang.io.stdout',
'',
'[args...] > app',
' stdout "Hello, world!" > @',
].join('\n');
}
2 changes: 2 additions & 0 deletions test/commands/test_dataize.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ describe('dataize', function() {
'dataize', 'foo.bar.app', 'Jeff',
'--verbose',
'--stack=64M',
'--clean',
'-s', path.resolve(home, 'src'),
'-t', path.resolve(home, 'target'),
]);
assert(stdout.includes('Hello, Jeff!'), stdout);
assert(stdout.includes(`The directory ${path.resolve(home, 'target')} deleted`), stdout);
assert(!fs.existsSync(path.resolve('../../mvnw/target')));
done();
});
Expand Down

0 comments on commit b5e932b

Please sign in to comment.