Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuleAssertionMessage nested assertions are ignored #357

Closed
c71n93 opened this issue Apr 17, 2024 · 14 comments
Closed

RuleAssertionMessage nested assertions are ignored #357

c71n93 opened this issue Apr 17, 2024 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@c71n93
Copy link

c71n93 commented Apr 17, 2024

Related to #353. Check out this two examples that I faced with:

    @Test
    void findsAttributesConcurrently() throws InterruptedException {
        final int threads = Runtime.getRuntime().availableProcessors() + 10;
        final ExecutorService service = Executors.newFixedThreadPool(threads);
        final PhPackage pckg = new PhPackage(PhPackageTest.DEFAULT_PACKAGE);
        final Set<Integer> basket = Collections.synchronizedSet(new HashSet<>(threads));
        final CountDownLatch latch = new CountDownLatch(1);
        Stream.generate(
            () -> (Runnable) () -> {
                try {
                    latch.await();
                    basket.add(System.identityHashCode(pckg.take("goto")));
                } catch (final InterruptedException exception) {
                    Thread.currentThread().interrupt();
                    throw new IllegalStateException(
                        "The testing thread was interrupted, current basket size %d",
                        exception
                    );
                }
            }
        ).limit(threads).forEach(service::submit);
        latch.countDown();
        service.shutdown();
        if (service.awaitTermination(1, TimeUnit.SECONDS)) {
            MatcherAssert.assertThat(
                "TO ADD ASSERTION MESSAGE",
                basket.size(),
                Matchers.equalTo(threads)
            );
        } else {
            throw new IllegalStateException(
                String.format(
                    "Failed to wait for threads to finish. Current basket size %d, but expected %d",
                    basket.size(),
                    threads
                )
            );
        }
    }
    /**
     * Integration test.
     * @param yml The YAML
     * @throws IOException If fails
     */
    @ParameterizedTest
    @Tag("slow")
    @ExtendWith(WeAreOnline.class)
    @SuppressWarnings("unchecked")
    @ClasspathSource(value = "org/eolang/snippets/", glob = "**.yaml")
    void runsAllSnippets(final String yml) throws IOException {
        final Yaml yaml = new Yaml();
        final Map<String, Object> map = yaml.load(yml);
        final String file = map.get("file").toString();
        Assumptions.assumeFalse(map.containsKey("skip"));
        new Farea(this.temp).together(
            f -> {
                f.properties()
                    .set("project.build.sourceEncoding", "UTF-8")
                    .set("project.reporting.outputEncoding", "UTF-8");
                f.files()
                    .file(String.format("src/main/eo/%s", file))
                    .write(String.format("%s\n", map.get("eo")))
                    .show();
                final Path runtime = Paths.get(System.getProperty("user.dir"))
                    .resolve("src/main/eo");
                final Collection<Path> sources = Files.walk(runtime)
                    .filter(src -> !src.toFile().isDirectory())
                    .collect(Collectors.toList());
                for (final Path src : sources) {
                    f.files()
                        .file(String.format("src/main/eo/%s", runtime.relativize(src)))
                        .write(new UncheckedText(new TextOf(src)).asString())
                        .show();
                }
                f.dependencies()
                    .appendItself();
                f.build()
                    .plugins()
                    .append(
                        "org.eolang",
                        "eo-maven-plugin",
                        System.getProperty("eo.version", "1.0-SNAPSHOT")
                    )
                    .phase("generate-sources")
                    .goals("register", "assemble", "verify", "transpile")
                    .configuration()
                    .set("failOnWarnings", "true");
                f.build()
                    .plugins()
                    .append("org.codehaus.mojo", "exec-maven-plugin", "3.1.1")
                    .phase("test")
                    .goals("java")
                    .configuration()
                    .set("mainClass", "org.eolang.Main")
                    .set("arguments", map.get("args"));
                f.exec("clean", "test");
                MatcherAssert.assertThat(
                    String.format("'%s' printed something wrong", yml),
                    f.log(),
                    Matchers.allOf(
                        new Mapped<>(
                            ptn -> Matchers.matchesPattern(
                                Pattern.compile(ptn, Pattern.DOTALL | Pattern.MULTILINE)
                            ),
                            (Iterable<String>) map.get("out")
                        )
                    )
                );
            }
        );
    }

Both of them have assertion message, however jtcop gives such outputs:

[ERROR]         1) Method findsAttributesConcurrently doesn't have assertion statements.
[ERROR]         Please add at least one assertion statement to the test method.
[ERROR]         You can also ignore the rule by adding @SuppressWarnings("JTCOP.RuleAssertionMessage") annotation.
[ERROR]         Rule: RuleAssertionMessage.
[ERROR]         1) Method runsAllSnippets doesn't have assertion statements.
[ERROR]         Please add at least one assertion statement to the test method.
[ERROR]         You can also ignore the rule by adding @SuppressWarnings("JTCOP.RuleAssertionMessage") annotation.
[ERROR]         Rule: RuleAssertionMessage.

@volodya-lombrozo Please, make sure that nested assertion are handled correctly.

@volodya-lombrozo
Copy link
Owner

@c71n93 Thank you for the reporting this bug! Most probably I just missed this cases. I'll check them soon.

@0pdd
Copy link
Collaborator

0pdd commented Apr 18, 2024

@c71n93 2 puzzles #359, #360 are still not solved.

@volodya-lombrozo
Copy link
Owner

@rultor release, tag is 1.2.3, title is 1.2.3.

@rultor
Copy link
Collaborator

rultor commented Apr 18, 2024

@rultor release, tag is 1.2.3, title is 1.2.3.

@volodya-lombrozo OK, I will release it now. Please check the progress here

@rultor
Copy link
Collaborator

rultor commented Apr 18, 2024

@rultor release, tag is 1.2.3, title is 1.2.3.

@volodya-lombrozo Done! FYI, the full log is here (took me 5min)

@volodya-lombrozo
Copy link
Owner

@c71n93 The issue should be solved in the 1.2.3 version. Could you check it please?

@c71n93
Copy link
Author

c71n93 commented Apr 18, 2024

@volodya-lombrozo still have this message:

[ERROR]         1) Method runsAllSnippets doesn't have assertion statements.
[ERROR]         Please add at least one assertion statement to the test method.
[ERROR]         You can also ignore the rule by adding @SuppressWarnings("JTCOP.RuleAssertionMessage") annotation.
[ERROR]         Rule: RuleAssertionMessage.

(this is the second example from the issue)

But the first one is fixed!

@volodya-lombrozo
Copy link
Owner

I see. Ok, I will take a look.

@volodya-lombrozo
Copy link
Owner

@rultor release, tag is 1.2.4, title is 1.2.4.

@rultor
Copy link
Collaborator

rultor commented Apr 19, 2024

@rultor release, tag is 1.2.4, title is 1.2.4.

@volodya-lombrozo OK, I will release it now. Please check the progress here

@rultor
Copy link
Collaborator

rultor commented Apr 19, 2024

@rultor release, tag is 1.2.4, title is 1.2.4.

@volodya-lombrozo Done! FYI, the full log is here (took me 5min)

@volodya-lombrozo
Copy link
Owner

@c71n93 Most probably, the issue is solved in the 1.2.4 version. Could you check it again please?

@c71n93
Copy link
Author

c71n93 commented Apr 19, 2024

@volodya-lombrozo yes, it solved, thanks!

@c71n93 c71n93 closed this as completed Apr 19, 2024
h1alexbel pushed a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
@0pdd
Copy link
Collaborator

0pdd commented Aug 24, 2024

@c71n93 all 2 puzzles are solved here: #359, #360.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants