Karl Heinz Marbaise created SUREFIRE-2113:
---------------------------------------------

             Summary: @TempDir does not correctly work
                 Key: SUREFIRE-2113
                 URL: https://issues.apache.org/jira/browse/SUREFIRE-2113
             Project: Maven Surefire
          Issue Type: Bug
          Components: JUnit 5.x support
    Affects Versions: 3.0.0-M7, 2.22.2
            Reporter: Karl Heinz Marbaise


Having the following test:
{code:java}
class TempDirTest {
  @Test
  void testTempDir(@TempDir Path tmpdir) {
    System.out.println("@TempDir : " + tmpdir);
    System.out.println("java.io.tmpdir : " + 
System.getProperty("java.io.tmpdir"));

    Path actual = tmpdir.getParent().toAbsolutePath();
    Path expected = Path.of(System.getProperty("java.io.tmpdir"));

    Assertions.assertEquals(expected, actual);
  }
}
{code}
If I run via:
{code}
mvn -Djava.io.tmpdir=/tmp/custom clean test
{code}
within the following environment:
{code}
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /Users/khm/tools/maven
Java version: 11.0.15, vendor: Azul Systems, Inc., runtime: 
/Users/khm/.sdkman/candidates/java/11.0.15-zulu/zulu-11.jdk/Contents/Home
Default locale: en_DE, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "aarch64", family: "mac"
```
The given test succeeds.

If I use the following environment (changed JDK version):
{code}
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /Users/khm/tools/maven
Java version: 17.0.4, vendor: Azul Systems, Inc., runtime: 
/Users/khm/.sdkman/candidates/java/17.0.4-zulu/zulu-17.jdk/Contents/Home
Default locale: en_DE, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "aarch64", family: "mac"
{code}
The given test fails:
{code}
[INFO] -------------------------------------------------------
[INFO] Running org.example.TempDirTest
@TempDir : 
/var/folders/wj/73qxv5hd6p573p9ytbf4kcgh0000gn/T/junit2987236559648574880
java.io.tmpdir : /tmp/custom
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.027 s 
<<< FAILURE! - in org.example.TempDirTest
[ERROR] testTempDir{Path}  Time elapsed: 0.023 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: </tmp/custom> but was: 
</var/folders/wj/73qxv5hd6p573p9ytbf4kcgh0000gn/T>
        at org.example.TempDirTest.testTempDir(TempDirTest.java:18)

[INFO] 
[INFO] Results:
{code}
I've checked that with different combinations:

* Maven 3.8.6
* JUnit Jupiter 5.8.2 / 5.9.0
* Maven Surefire Plugin Version:
  * 2.22.2
  * 3.0.0-M7
  * [Platform Maven 
Plugin](https://github.com/sormuras/junit-platform-maven-plugin)

I have create a full [working 
example](https://github.com/khmarbaise/tempdir-annotation) which contains 
appropriate named branches for the different combinations.

I've also tested the same combinations with JDK 17/11 from liberica with the 
same result. Also with JDK18 the test fails.

After more checking I found out that via the standalone launcher, there is no 
problem at all. (no difference between jdk versions).
{code}
java -Djava.io.tmpdir=/tmp/custom -jar 
~/.m2/repository/org/junit/platform/junit-platform-console-standalone/1.9.0/junit-platform-console-standalone-1.9.0.jar
 -cp classes:target/test-classes --scan-classpath
{code}
The output:
{code}
@TempDir : /tmp/custom/junit17756560401872268189
java.io.tmpdir : /tmp/custom

Thanks for using JUnit! Support its development at https://junit.org/sponsoring

╷
├─ JUnit Jupiter ✔
│  └─ TempDirTest ✔
│     └─ testTempDir(Path) ✔
├─ JUnit Vintage ✔
└─ JUnit Platform Suite ✔

Test run finished after 51 ms
[         4 containers found      ]
[         0 containers skipped    ]
[         4 containers started    ]
[         0 containers aborted    ]
[         4 containers successful ]
[         0 containers failed     ]
[         1 tests found           ]
[         0 tests skipped         ]
[         1 tests started         ]
[         0 tests aborted         ]
[         1 tests successful      ]
[         0 tests failed          ]

{code}
Has someone an Idea what could cause such thing?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to