Skip to content

Commit

Permalink
Merge pull request #3645 from objectionary/3644
Browse files Browse the repository at this point in the history
check existence
  • Loading branch information
yegor256 authored Dec 13, 2024
2 parents e477279 + dcbf5c8 commit e1c11dc
Show file tree
Hide file tree
Showing 10 changed files with 576 additions and 81 deletions.
452 changes: 452 additions & 0 deletions .codenarc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/codenarc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
-maxPriority2Violations=50 \
-maxPriority3Violations=200 \
-failOnError=true \
-rulesetfiles=rulesets/basic.xml,rulesets/braces.xml,rulesets/comments.xml,rulesets/concurrency.xml,rulesets/convention.xml,rulesets/design.xml,rulesets/dry.xml,rulesets/enhanced.xml,rulesets/exceptions.xml,rulesets/formatting.xml,rulesets/generic.xml,rulesets/groovyism.xml,rulesets/imports.xml,rulesets/logging.xml,rulesets/naming.xml,rulesets/size.xml,rulesets/unnecessary.xml,rulesets/unused.xml
-rulesetfiles=file:.codenarc
2 changes: 1 addition & 1 deletion eo-parser/src/main/antlr4/org/eolang/parser/Phi.g4
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ lambdaBinding
;

FUNCTION
: [A-Z][A-Za-z_φ]*
: [A-Z][A-Z0-9a-z_φ]*
;

application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
hi-大家 ↦ ⟦ ⟧,
α0 ↦ Φ () () (),
α65536 ↦ Φ.r,
k ↦ ⟦ λ ⤍ FunctionName, α0 ↦ ⟦ λ ⤍ FunctionName, Δ ⤍ 42- ⟧ ⟧,
k ↦ ⟦ λ ⤍ Function_Name_i64, α0 ↦ ⟦ λ ⤍ FunctionName, Δ ⤍ 42- ⟧ ⟧,
terminator-application ↦ ⊥ (t ↦ ξ.t),
terminator-dispatch ↦ ⊥.t,
string ↦ "Hello",
Expand Down
15 changes: 10 additions & 5 deletions eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ SOFTWARE.
<artifactId>eo-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<foreign>${project.basedir}/target/eo-foreign.csv</foreign>
<foreign>${project.build.directory}/eo-foreign.csv</foreign>
<foreignFormat>csv</foreignFormat>
<failOnWarning>false</failOnWarning>
<offline>true</offline>
<unphiOutputDir>${project.build.directory}/eo/unphi</unphiOutputDir>
</configuration>
<executions>
<execution>
Expand All @@ -226,6 +227,7 @@ SOFTWARE.
<goal>lint</goal>
<goal>transpile</goal>
<goal>xmir-to-phi</goal>
<goal>phi-to-xmir</goal>
<goal>copy</goal>
<goal>unplace</goal>
<goal>unspile</goal>
Expand All @@ -249,19 +251,22 @@ SOFTWARE.
<goal>assemble</goal>
<goal>lint</goal>
<goal>xmir-to-phi</goal>
<goal>phi-to-xmir</goal>
<goal>transpile</goal>
<goal>binarize</goal>
</goals>
<configuration>
<scope>test</scope>
<sourcesDir>${project.basedir}/src/test/eo</sourcesDir>
<targetDir>${project.basedir}/target/eo-test</targetDir>
<targetDir>${project.build.directory}/eo-test</targetDir>
<phiInputDir>${project.build.directory}/eo-test/2-optimize</phiInputDir>
<phiOutputDir>${project.build.directory}/eo-test/phi</phiOutputDir>
<unphiInputDir>${project.build.directory}/eo-test/phi</unphiInputDir>
<unphiOutputDir>${project.build.directory}/eo-test/unphi</unphiOutputDir>
<addSourcesRoot>false</addSourcesRoot>
<addTestSourcesRoot>true</addTestSourcesRoot>
<failOnWarning>false</failOnWarning>
<generatedDir>
${project.basedir}/target/generated-test-sources
</generatedDir>
<generatedDir>${project.build.directory}/generated-test-sources</generatedDir>
<withRuntimeDependency>false</withRuntimeDependency>
<placeBinariesThatHaveSources>true</placeBinariesThatHaveSources>
</configuration>
Expand Down
56 changes: 24 additions & 32 deletions eo-runtime/src/test/groovy/check-all-java-classes-compiled.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,33 @@ import java.nio.file.Files
import java.nio.file.Path
import java.util.stream.Collectors

println 'Verify that all java classes were compiled successfully'

Path binaries = basedir.toPath()
.resolve("target")
.resolve("classes")
.resolve("org")
.resolve("eolang");
.resolve("target")
.resolve("classes")
.resolve("org")
.resolve("eolang");
Path classes = basedir.toPath()
.resolve("src")
.resolve("main")
.resolve("java")
.resolve("org")
.resolve("eolang")
.resolve("src")
.resolve("main")
.resolve("java")
.resolve("org")
.resolve("eolang")
Set<String> expected = Files.walk(classes)
.filter(it -> {
it.toString().endsWith(".java")
})
.map(Path::getFileName)
.map(Path::toString)
.map(it -> {
return it.replace(".java", ".class")
}).collect(Collectors.toSet())
.filter(it -> {
it.toString().endsWith(".java")
})
.map(Path::getFileName)
.map(Path::toString)
.map(it -> {
return it.replace(".java", ".class")
}).collect(Collectors.toSet())
Set<String> actual = Files.walk(binaries)
.filter(it -> {
it.toString().endsWith(".class")
})
.map(Path::getFileName)
.map(Path::toString)
.collect(Collectors.toSet())
.filter(it -> {
it.toString().endsWith(".class")
})
.map(Path::getFileName)
.map(Path::toString)
.collect(Collectors.toSet())
if (!actual.containsAll(expected)) {
throw new IllegalStateException(
String.format(
"Not all classes are compiled\nExpected %s\nActual %s",
expected,
actual
)
)
fail("Not all classes are compiled\nExpected ${expected}\nActual ${actual}")
}
43 changes: 22 additions & 21 deletions eo-runtime/src/test/groovy/check-folders-numbering.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@

import java.util.stream.Collectors

target = basedir.toPath().resolve("target").resolve("eo")
target = basedir.toPath().resolve('target/eo')
List<File> directories = target.toFile().listFiles(new FileFilter() {
@Override
boolean accept(final File pathname) {
return pathname.isDirectory()
}
@Override
boolean accept(final File pathname) {
return pathname.isDirectory()
}
})
List<String> allowed = [
'1-parse',
'2-optimize',
'3-shake',
'4-pull',
'5-resolve',
'6-lint',
'7-pre',
'8-transpile',
'phi'
var allowed = [
'1-parse',
'2-optimize',
'3-shake',
'4-pull',
'5-resolve',
'6-lint',
'7-pre',
'8-transpile',
'phi',
'unphi'
]
List<File> allowedDirs = allowed.stream()
.map { target.resolve(it).toFile() }
.collect(Collectors.toList())
.map { target.resolve(it).toFile() }
.collect(Collectors.toList())

for (dir in directories) {
if (!allowedDirs.contains(dir)) {
fail(String.format("The directory '%s' is not expected to be here. Allowed directories %s", dir.name, allowed));
}
if (!allowedDirs.contains(dir)) {
fail("The directory '${dir.name}' is not expected to be here");
}
}
true
16 changes: 4 additions & 12 deletions eo-runtime/src/test/groovy/check-runtime-deps.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@
*/
import groovy.xml.XmlSlurper

def pom = new File("pom.xml").text
def pom = new File('pom.xml').text
def project = new XmlSlurper().parseText(pom)

println 'Verify that there are no any dependencies in eo-runtime except those that are needed for tests'

project.dependencies.dependency.each {
if (it.scope.text() != 'test' && it.scope.text() != 'provided')
fail(
String.format(
'Dependency %s.%s must be in "test" or "provided" scope',
it.groupId.text(), it.artifactId.text()
)
)
if (it.scope.text() != 'test' && it.scope.text() != 'provided') {
fail("Dependency ${it.groupId.text()}.${it.artifactId.text()} must be in either 'test' or 'provided' scope")
}
}

true
54 changes: 54 additions & 0 deletions eo-runtime/src/test/groovy/check-target-files.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 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.
*/

import java.nio.file.Paths

var expected = [
'eo-foreign.csv',
'eo/1-parse/org/eolang/bytes.xmir',
'eo/1-parse/org/eolang/fs/dir.xmir',
'eo/2-optimize/org/eolang/error.xmir',
'eo/2-optimize/org/eolang/sys/os.xmir',
'eo/6-lint/org/eolang/go.xmir',
'eo/8-transpile/org/eolang/malloc.xmir',
'eo/phi/org/eolang/number.phi',
'eo/unphi/org/eolang/number.xmir',
'eo-test/1-parse/org/eolang/bool-tests.xmir',
'eo-test/2-optimize/org/eolang/go-tests.xmir',
'eo-test/6-lint/org/eolang/dataized-tests.xmir',
'eo-test/8-transpile/org/eolang/runtime-tests.xmir',
'eo-test/phi/org/eolang/number-tests.phi',
'eo-test/unphi/org/eolang/number-tests.xmir',
'generated-sources/EOorg/EOeolang/EOdataized.java',
'generated-sources/EOorg/EOeolang/EOnet/EOsocket.java',
'generated-test-sources/EOorg/EOeolang/EOand_with_zeroTest.java',
'classes/EO-SOURCES/org/eolang/false.eo',
]

for (path in expected) {
var f = Paths.get('eo-runtime/target').resolve(path).toFile()
if (!f.exists()) {
fail("The file '${f}' is not present")
}
}
15 changes: 7 additions & 8 deletions eo-runtime/src/test/groovy/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ import java.nio.file.Path
* To add new validation create new script in this folder and add it
* to the list below.
*/
Path folder = basedir.toPath().resolve("src").resolve("test").resolve("groovy")
tests = [
'check-folders-numbering.groovy',
'check-all-java-classes-compiled.groovy',
'check-runtime-deps.groovy'
Path folder = basedir.toPath().resolve('src/test/groovy')
var tests = [
'check-folders-numbering.groovy',
'check-all-java-classes-compiled.groovy',
'check-runtime-deps.groovy',
'check-target-files.groovy',
]
for (it in tests) {
def res = evaluate folder.resolve(it).toFile()
println String.format('Verified with %s - OK. Result: %s', it, res)
evaluate folder.resolve(it).toFile()
}
true

0 comments on commit e1c11dc

Please sign in to comment.