konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.55k stars 262 forks source link

LinkedList offer functions adds item incorrectly at the beginning of the List #772 #773

Closed ldubost closed 8 months ago

ldubost commented 9 months ago

This is a fix for issue #772

konsoletyper commented 9 months ago

Can you please provide a test?

Ihromant commented 8 months ago

@konsoletyper I suppose author won't add test. But he's right. Here is a test that proves his PR, it can be added after the merge. Strangely nobody caught this earlier.

@Test
    public void testOffer() {
        LinkedList<String> list = new LinkedList<>();
        list.offer("1");
        list.offer("2");
        assertEquals("1", list.getFirst());
        assertEquals("2", list.getLast());
    }
ldubost commented 8 months ago

Actually I wanted to provide a test, which I wrote. But I could not find how to run the tests to verify the test was ok.

konsoletyper commented 8 months ago

See test module. All classlib tests are located in org.teavm.classlib package, in sub-packages named after Java class library packages. For your particular case, there's org.teavm.classlib.java.util.LinkedListTest class. To run tests, run

./gradlew -Pteavm.tests.wasi=false -Pteavm.tests.c=true test

or to test single class

./gradlew -Pteavm.tests.wasi=false -Pteavm.tests.c=true :tests:test --tests "org.teavm.classlib.java.util.LinkedListTest"

You can also use IDE to run particular test class or method, but by default TeaVM may try to run tests for C and WASI BE, which require additional setup. Unless you want to setup environment, you can open gradle.properties file and if you find there following lines:

teavm.tests.wasi=true
teavm.tests.c=true

comment them out.