From 485a5e35c7ad256de8563fdc09f48c89f3171214 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Fri, 22 Dec 2023 10:46:29 +0300 Subject: [PATCH] #205 verify --- src/commands/verify.js | 44 +++++++++++++++++++++++++++++ test/commands/test_verify.js | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/commands/verify.js create mode 100644 test/commands/test_verify.js diff --git a/src/commands/verify.js b/src/commands/verify.js new file mode 100644 index 0000000..42bb499 --- /dev/null +++ b/src/commands/verify.js @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2022-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +const path = require('path'); +const mvnw = require('../mvnw'); + +/** + * Command to verify .XMIR files. + * @param {Hash} opts - All options + * @return {Promise} of assemble task + */ +module.exports = function(opts) { + return mvnw([ + 'eo:verify', + '-Deo.version=' + opts.parser, + '-Deo.hash=' + (opts.hash ? opts.hash : opts.parser), + opts.verbose ? '--errors' : '', + opts.verbose ? '' : '--quiet', + ], opts.target, opts.batch).then((r) => { + console.info('EO program verified in %s', path.resolve(opts.target)); + return r; + }); +}; diff --git a/test/commands/test_verify.js b/test/commands/test_verify.js new file mode 100644 index 0000000..93a4742 --- /dev/null +++ b/test/commands/test_verify.js @@ -0,0 +1,55 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2022-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const {runSync, assertFilesExist} = require('../helpers'); + +describe('verify', function() { + it('verifies a simple .EO program', function(done) { + home = path.resolve('temp/test-assemble/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\n'); + const stdout = runSync([ + 'verify', + '--verbose', + '--track-optimization-steps', + '-s', path.resolve(home, 'src'), + '-t', path.resolve(home, 'target'), + ]); + assertFilesExist( + stdout, home, + [ + 'target/eo-foreign.json', + 'target/1-parse/simple.xmir', + 'target/2-optimization-steps/simple', + 'target/2-optimize/simple.xmir', + ] + ); + assert(!fs.existsSync(path.resolve('../../mvnw/target'))); + done(); + }); +});