Skip to content

Commit

Permalink
#11 test task implemented and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 19, 2022
1 parent fdde27b commit 72996e3
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 29 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/itest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
java: [11, 17, 18]
node: [12, 14, 16]
java: [11, 18]
node: [12, 16]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand All @@ -23,4 +23,5 @@ jobs:
distribution: 'zulu'
java-version: ${{ matrix.java }}
- run: npm install
- run: cd itest && node ../src/eoc.js dataize foo.program
- run: cd itest && node ../src/eoc.js dataize program
- run: cd itest && node ../src/eoc.js test
6 changes: 6 additions & 0 deletions itest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ it works:
$ ../src/eoc.js dataize foo.program
```

Then, you can execute the unit tests too:

```
$ ../src/eoc.js test
```

If doesn't work, submit an issue.
6 changes: 0 additions & 6 deletions itest/foo/program.eo

This file was deleted.

9 changes: 0 additions & 9 deletions itest/foo/story.eo

This file was deleted.

27 changes: 27 additions & 0 deletions itest/program.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# The MIT License (MIT)
#
# Copyright (c) 2022 Yegor Bugayenko
#
# 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.

+alias story

[args...] > program
QQ.io.stdout > @
story
31 changes: 31 additions & 0 deletions itest/story-test.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# The MIT License (MIT)
#
# Copyright (c) 2022 Yegor Bugayenko
#
# 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.

+junit
+alias org.eolang.hamcrest.assert-that
+alias story

[] > story-is-long-enough
assert-that > @
story.length
$.is
$.greater-than 1
29 changes: 29 additions & 0 deletions itest/story.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The MIT License (MIT)
#
# Copyright (c) 2022 Yegor Bugayenko
#
# 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.

[] > story
QQ.txt.sprintf > @
"Hello, Mr. #%d!\n"
as-int.
times.
random
100.0
8 changes: 8 additions & 0 deletions mvnw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ SOFTWARE.
<sourceDirectory>${eo.generatedDir}</sourceDirectory>
<directory>${eo.targetDir}</directory>
<outputDirectory>${eo.targetDir}/classes</outputDirectory>
<testOutputDirectory>${eo.targetDir}/classes</testOutputDirectory>
<plugins>
<plugin>
<groupId>org.eolang</groupId>
Expand Down Expand Up @@ -72,6 +73,13 @@ SOFTWARE.
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<failIfNoTests>true</failIfNoTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
38 changes: 38 additions & 0 deletions src/commands/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /usr/bin/env node
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 Yegor Bugayenko
*
* 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 mvnwSync = require('../mvnw');
const path = require('path');

/**
* Command to run all available unit tests.
* @param {Hash} opts - All options
*/
module.exports = function test(opts) {
mvnwSync([
'surefire:test',
`-Deo.targetDir=${path.resolve(opts.target)}`,
]);
};
14 changes: 14 additions & 0 deletions src/eoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const transpile = require('./commands/transpile');
const compile = require('./commands/compile');
const link = require('./commands/link');
const dataize = require('./commands/dataize');
const test = require('./commands/test');

program
.name('eoc')
Expand Down Expand Up @@ -118,6 +119,19 @@ program.command('dataize')
dataize(program.args[1], program.opts());
});

program.command('test')
.description('run all visible unit tests')
.action((str, opts) => {
if (program.opts().alone == undefined) {
register(program.opts());
assemble(program.opts());
transpile(program.opts());
compile(program.opts());
link(program.opts());
}
test(program.opts());
});

try {
program.parse(process.argv);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');

describe('eoc', function() {
describe('assemble', function() {
it('assembles a simple .EO program', function(done) {
home = path.resolve('temp/test-assemble/simple');
fs.rmSync(home, {recursive: true, force: true});
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
const assert = require('assert');
const {runSync} = require('../helpers');

describe('eoc', function() {
describe('audit', function() {
it('audits all packages', function(done) {
const stdout = runSync(['audit']);
assert(stdout.includes('Apache Maven'));
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const fs = require('fs');
const path = require('path');
const {runSync} = require('../helpers');

describe('eoc', function() {
describe('clean', function() {
it('deletes all temporary files', function(done) {
home = path.resolve('temp/test-clean/simple');
fs.rmSync(home, {recursive: true, force: true});
Expand Down
3 changes: 1 addition & 2 deletions test/commands/test_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');

describe('eoc', function() {
describe('compile', function() {
it('compiles a simple .EO program into Java bytecode .class files', function(done) {
home = path.resolve('temp/test-compile/simple');
fs.rmSync(home, {recursive: true, force: true});
Expand All @@ -40,7 +40,6 @@ describe('eoc', function() {
'',
'[args...] > app',
' stdout "Hello, world!" > @',
'',
].join('\n')
);
const stdout = runSync([
Expand Down
3 changes: 1 addition & 2 deletions test/commands/test_dataize.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const assert = require('assert');
const path = require('path');
const {runSync} = require('../helpers');

describe('eoc', function() {
describe('dataize', function() {
it('runs a single executable .JAR and dataizes an object', function(done) {
home = path.resolve('temp/test-run/simple');
fs.rmSync(home, {recursive: true, force: true});
Expand All @@ -40,7 +40,6 @@ describe('eoc', function() {
'',
'[args...] > app',
' stdout "Hello, world!" > @',
'',
].join('\n')
);
const stdout = runSync([
Expand Down
3 changes: 1 addition & 2 deletions test/commands/test_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');

describe('eoc', function() {
describe('link', function() {
it('compiles a simple .EO program into an executable .JAR', function(done) {
home = path.resolve('temp/test-link/simple');
fs.rmSync(home, {recursive: true, force: true});
Expand All @@ -40,7 +40,6 @@ describe('eoc', function() {
'',
'[args...] > app',
' stdout "Hello, world!" > @',
'',
].join('\n')
);
const stdout = runSync([
Expand Down
2 changes: 1 addition & 1 deletion test/commands/test_register.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');

describe('eoc', function() {
describe('register', function() {
it('registers a simple .EO program', function(done) {
home = path.resolve('temp/test-register/simple');
fs.rmSync(home, {recursive: true, force: true});
Expand Down
59 changes: 59 additions & 0 deletions test/commands/test_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 Yegor Bugayenko
*
* 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 fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');

describe('test', function() {
it('executes a single unit test', function(done) {
home = path.resolve('temp/test-test/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(
path.resolve(home, 'src/simple-test.eo'),
[
'+junit',
'+alias org.eolang.hamcrest.assert-that',
'',
'[] > simple-comparison-works',
' assert-that > @',
' 10',
' $.greater-than',
' 5',
].join('\n')
);
const stdout = runSync([
'test', '-s', path.resolve(home, 'src'), '-t', path.resolve(home, 'target'),
]);
assertFilesExist(
stdout, home,
[
'target/generated-sources/EOsimple_comparison_worksTest.java',
'target/classes/EOsimple_comparison_worksTest.class',
]
);
done();
});
});
2 changes: 1 addition & 1 deletion test/commands/test_transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');

describe('eoc', function() {
describe('transpile', function() {
it('transpiles a simple .EO program', function(done) {
home = path.resolve('temp/test-transpile/simple');
fs.rmSync(home, {recursive: true, force: true});
Expand Down

0 comments on commit 72996e3

Please sign in to comment.