feat(#3251): fix tests and style

This commit is contained in:
maxonfjvipon 2024-08-01 10:33:43 +03:00
parent 77c94da3a1
commit 697638ca7d
No known key found for this signature in database
GPG Key ID: D8563899D473D273
17 changed files with 219 additions and 28 deletions

View File

@ -25,10 +25,20 @@
# package name contains capital letter and such names are conventional.
---
exclude_paths:
- "eo-runtime/src/main/java/EOorg/EOeolang/EOio/EOconsole$EOread$EOread_bytes.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOio/EOconsole$EOwrite$EOwritten_bytes.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOconsoleTest.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOsys/EOuname$EOφ.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOsys/package-info.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOnumberTest.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/package-info.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOmade$EOmkdir.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOtmpfile$EOtouch.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOwalk.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOdeleted$EOdelete.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOexists.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOis_directory.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOmoved$EOmove.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOopen$EOfile_stream$EOread$EOread_bytes.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOopen$EOfile_stream$EOread$EOwritten_bytes.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOopen$EOprocess_file.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOresolved$EOresolve.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOsize.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOtouched$EOtouch.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/Files.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/EOgetenv.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/EOos$EOname.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOfs/FilesTest.java"

View File

@ -195,6 +195,7 @@ public final class FakeMaven {
* @return Workspace after executing Mojo.
* @throws java.io.IOException If some problem with filesystem has happened.
* @checkstyle ExecutableStatementCountCheck (100 lines)
* @checkstyle JavaNCSSCheck (100 lines)
*/
public <T extends AbstractMojo> FakeMaven execute(final Class<T> mojo) throws IOException {
if (this.defaults) {

View File

@ -90,7 +90,7 @@
[] > tmpfile
if. > @
^.exists
QQ.fs.file touched.as-bytes.as-string
QQ.fs.file touch.as-bytes.as-string
error
sprintf
"Directory %s does not exist, can't create temporary file"

View File

@ -74,11 +74,13 @@ public final class EOdir$EOwalk extends PhDefault implements Atom {
.map(p -> p.toAbsolutePath().toString())
.map(p -> p.substring(p.indexOf(path.toString())))
.filter(p -> matcher.matches(Paths.get(p)))
.map(p -> {
final Phi file = Phi.Φ.take("org.eolang.fs.file").copy();
file.put(0, new ToPhi(p));
return file;
})
.map(
p -> {
final Phi file = Phi.Φ.take("org.eolang.fs.file").copy();
file.put(0, new ToPhi(p));
return file;
}
)
.toArray(Phi[]::new)
);
}

View File

@ -44,7 +44,9 @@ import org.eolang.XmirObject;
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.open.file-stream.read.read-bytes")
public final class EOfile$EOopen$EOfile_stream$EOread$EOread_bytes extends PhDefault implements Atom {
public final class EOfile$EOopen$EOfile_stream$EOread$EOread_bytes
extends PhDefault
implements Atom {
/**
* Ctor.

View File

@ -44,7 +44,9 @@ import org.eolang.XmirObject;
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.open.file-stream.write.written-bytes")
public final class EOfile$EOopen$EOfile_stream$EOwrite$EOwritten_bytes extends PhDefault implements Atom {
public final class EOfile$EOopen$EOfile_stream$EOwrite$EOwritten_bytes
extends PhDefault
implements Atom {
/**
* Ctor.

View File

@ -43,7 +43,7 @@ import org.eolang.XmirObject;
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.touched.touch")
public class EOfile$EOtouched$EOtouch extends PhDefault implements Atom {
public final class EOfile$EOtouched$EOtouch extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
return new Data.ToPhi(

View File

@ -45,7 +45,7 @@ import org.eolang.Versionized;
@Versionized
final class Files {
/**
* Files instance
* Files instance.
*/
static final Files INSTANCE = new Files();
@ -67,10 +67,13 @@ final class Files {
* @throws FileNotFoundException If can't open file
*/
void open(final String name) throws FileNotFoundException {
this.streams.putIfAbsent(name, new Object[] {
new FileInputStream(name),
new FileOutputStream(name, true)
});
this.streams.putIfAbsent(
name,
new Object[] {
new FileInputStream(name),
new FileOutputStream(name, true),
}
);
}
/**

View File

@ -34,7 +34,7 @@ import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* Os.name
* Os.name.
* @since 0.40
* @checkstyle TypeNameCheck (5 lines)
*/

View File

@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.fs.dir
+alias org.eolang.fs.file
+alias org.eolang.fs.tmpdir
+alias org.eolang.txt.sprintf
@ -80,7 +81,7 @@
# Test.
[] > resolves-and-touches
tmpdir.resolved "foo/bar" > resolved
dir (tmpdir.resolved "foo/bar") > resolved
resolved.tmpfile > f
seq > @
*

View File

@ -41,7 +41,7 @@ import org.junit.jupiter.api.Test;
* Test cases for {@link Cages}.
* @since 0.36.0
*/
class CagesTest {
final class CagesTest {
@Test
void initializesObjectForTheFirstTime() {
final Phi phi = new PhFake();

View File

@ -1,4 +1,140 @@
/*
* 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.
*/
/*
* @checkstyle PackageNameCheck (10 lines)
*/
package EOorg.EOeolang.EOfs;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eolang.ExFailure;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
/**
* Test case for {@link Files}.
* @since 0.40
*/
final class FilesTest {
/**
* Files instance.
*/
private static final Files INSTANCE = Files.INSTANCE;
@Test
void opensWithoutErrors(@TempDir final Path dir) {
Assertions.assertDoesNotThrow(
() -> FilesTest.INSTANCE.open(FilesTest.tempFile(dir)),
"File should be opened without errors"
);
}
@Test
void throwsOnReadingWithoutOpening(@TempDir final Path dir) {
Assertions.assertThrows(
ExFailure.class,
() -> FilesTest.INSTANCE.read(
FilesTest.tempFile(dir), 10
),
"File should not allow to read before opening"
);
}
@Test
void throwsOnWritingWithoutOpening(@TempDir final Path dir) {
Assertions.assertThrows(
ExFailure.class,
() -> FilesTest.INSTANCE.write(
FilesTest.tempFile(dir), new byte[]{0x01}
),
"File should not allow to write before opening"
);
}
@Test
void throwsOnClosingWithoutOpening(@TempDir final Path dir) {
Assertions.assertThrows(
ExFailure.class,
() -> FilesTest.INSTANCE.close(
FilesTest.tempFile(dir)
),
"File should not allow to close before opening"
);
}
@Test
void readsFromFile(@TempDir final Path dir) throws IOException {
final String file = FilesTest.tempFile(dir);
final FileWriter writer = new FileWriter(
Paths.get(file).toFile()
);
writer.write("Hello, world");
writer.close();
FilesTest.INSTANCE.open(file);
MatcherAssert.assertThat(
"The string should have been read from file",
FilesTest.INSTANCE.read(file, 12),
Matchers.equalTo("Hello, world".getBytes(StandardCharsets.UTF_8))
);
FilesTest.INSTANCE.close(file);
}
@Test
void writesToFile(@TempDir final Path dir) throws IOException {
final String file = FilesTest.tempFile(dir);
final FileWriter writer = new FileWriter(
Paths.get(file).toFile()
);
writer.write("Hello, world");
writer.close();
FilesTest.INSTANCE.open(file);
FilesTest.INSTANCE.write(file, "!".getBytes(StandardCharsets.UTF_8));
MatcherAssert.assertThat(
"The string should have been read from file",
FilesTest.INSTANCE.read(file, 13),
Matchers.equalTo("Hello, world!".getBytes(StandardCharsets.UTF_8))
);
FilesTest.INSTANCE.close(file);
}
/**
* Creates temporary file in directory.
* @param dir Directory
* @return Absolute path to temp file
* @throws IOException If fails to create temp file
*/
private static String tempFile(final Path dir) throws IOException {
final Path file = java.nio.file.Files.createTempFile(dir, null, null);
file.toFile().deleteOnExit();
return file.toAbsolutePath().toString();
}
}

View File

@ -0,0 +1,34 @@
/*
* 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.
*/
/*
* @checkstyle PackageNameCheck (20 lines)
*/
/**
* EO-fs, tests.
*
* @since 0.40
*/
package EOorg.EOeolang.EOfs;

View File

@ -47,7 +47,7 @@ import org.junit.jupiter.api.Test;
* @since 0.1
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
public final class EOmallocTest {
final class EOmallocTest {
@Test
void freesMemory() {
final Dummy dummy = new Dummy();

View File

@ -53,7 +53,7 @@ import org.junit.jupiter.params.provider.CsvSource;
* @checkstyle TypeNameCheck (4 lines)
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
public final class EOnumberTest {
final class EOnumberTest {
@Test
void hasDifferentHashes() {

View File

@ -46,7 +46,7 @@ import org.junit.jupiter.api.Test;
*
* @since 0.19
*/
public final class EOtryTest {
final class EOtryTest {
@Test
public void catchesException() {

View File

@ -41,7 +41,7 @@ import org.junit.jupiter.api.Test;
*
* @since 0.19
*/
public final class HeapsTest {
final class HeapsTest {
/**
* Heaps.
*/