Skip to content

Commit

Permalink
#3636: tested and better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 13, 2024
1 parent d0bf3b8 commit fc8fbec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eo-parser/src/main/java/org/eolang/parser/StrictXmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private static File fetch(final String uri, final Path path) {
new BytesOf(new ResourceOf("XMIR.xsd"))
).asBytes()
);
Logger.debug(StrictXmir.class, "XSD copied to %[file]s", path);
} catch (final IOException ex) {
throw new IllegalArgumentException(
String.format("Failed to save %s to %s", uri, path),
Expand Down Expand Up @@ -227,6 +228,11 @@ private static File download(final String uri, final Path path) {
new BytesOf(new InputOf(new URI(uri)))
).asBytes()
);
Logger.debug(
StrictXmir.class,
"XSD downloaded from %s and copied to %[file]s",
uri, path
);
break;
} catch (final IOException ex) {
if (attempt < 3) {
Expand Down
37 changes: 37 additions & 0 deletions eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.parser;

import com.jcabi.manifests.Manifests;
import com.jcabi.xml.XMLDocument;
import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
Expand Down Expand Up @@ -73,6 +74,42 @@ void validatesXmir(@Mktmp final Path tmp) throws Exception {
);
}

@Test
@ExtendWith(MktmpResolver.class)
void validatesXmirWithLocalSchema(@Mktmp final Path tmp) throws Exception {
MatcherAssert.assertThat(
"validation should pass as normal",
new StrictXmir(
new Xmir(
new XMLDocument(
new Xembler(
new Directives()
.append(new DrProgram("foo3"))
.xpath("/program")
.attr(
"noNamespaceSchemaLocation xsi http://www.w3.org/2001/XMLSchema-instance",
String.format(
"https://www.eolang.org/xsd/XMIR-%s.xsd",
Manifests.read("EO-Version")
)
)
.add("objects")
).xml()
)
),
tmp
).validate(),
Matchers.emptyIterable()
);
MatcherAssert.assertThat(
"temporary XSD file created",
tmp.resolve(
String.format("XMIR-%s.xsd", Manifests.read("EO-Version"))
).toFile().exists(),
Matchers.is(true)
);
}

@Test
@ExtendWith(MktmpResolver.class)
void validatesXmirWithBrokenUri(@Mktmp final Path tmp) {
Expand Down

0 comments on commit fc8fbec

Please sign in to comment.