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

Tests loading resources don't work in Intellij triggered tests with BSP import #4427

Open
joan38 opened this issue Jan 29, 2025 · 5 comments
Labels
bug The issue represents an bug

Comments

@joan38
Copy link
Collaborator

joan38 commented Jan 29, 2025

Reproduce

mkdir mill-issue-4427 && cd $_

curl -L https://github.com/com-lihaoyi/mill/releases/download/0.12.5/0.12.5 > mill && chmod +x mill

cat > build.mill <<EOF
import mill._
import mill.scalalib._

object project extends ScalaModule {
  override def scalaVersion = "2.13.15"

  object test extends ScalaTests with TestModule.Munit {
    override def ivyDeps = Agg(ivy"org.scalameta::munit::1.0.4")
  }
}
EOF

cat > .mill-version <<EOF
0.12.5
EOF

mkdir -p project/test/src
cat > project/test/src/Test.scala <<EOF
class Test extends munit.FunSuite {
  test("Load resources") {
    assert(getClass.getResource(s"/somefile") != null, "Unable to find somefile in the resources")
  }
}
EOF

mkdir -p project/test/resources
cat > project/test/resources/somefile <<EOF
blablabla
EOF

The following works:

./mill __.test

But if you open the project in Intellij (loads with BSP), open the Test.scala file and run the test with the Run button next to the test decalaration:
Image
It fails to find the resource:

munit.FailException: /.../mill-issue-4427/project/test/src/Test.scala:3 Unable to find somefile in the resources
2:  test("Load resources") {
3:    assert(getClass.getResource(s"/somefile") != null, "Unable to find somefile in the resources")
4:  }

	at munit.FunSuite.assert(FunSuite.scala:11)
	at Test.$anonfun$new$1(Test.scala:3)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)

I tested a similar setup with Scala CLI and Intellij to make sure it's a mill issue and not an Intellij issue. Works fine with Scala CLI.

Thanks

@lefou
Copy link
Member

lefou commented Jan 30, 2025

Is there a reason you use Mill 0.12.3 to reproduce, which is not the latest at them time you opened this issue? Also, a quick idea: could you try to rename the project to e.g. project1. Maybe there is somewhere some special handling for the project dir, which is typically used for sbt projects to hold the project and meta-project files. I don't expect it, but let's eliminate this chance.

@lefou
Copy link
Member

lefou commented Jan 30, 2025

I can reproduce the issue with Mill 0.12.5-173-15dded. Changing the project dir doesn't change the outcome.

@joan38
Copy link
Collaborator Author

joan38 commented Jan 30, 2025

Sorry, I should have put the latest version. Editing the reproduction step with 0.12.5

@lefou
Copy link
Member

lefou commented Jan 30, 2025

The resources dir is properly registered in the IntelliJ project as Test Resources.

Image

I'm not convinced this is an issue in Mill. For a cross check, you should also open an issue in the IntelliJ Scala Plugin tracker.

@joan38
Copy link
Collaborator Author

joan38 commented Jan 31, 2025

I noticed this too and was thinking it's an Intellij bug.
But here is an example where it works fine with Mill 0.10.15 (does not work in 0.11.0):

mkdir mill-issue-4427-mill-older-works && cd $_

curl -L https://github.com/com-lihaoyi/mill/releases/download/0.12.5/0.12.5 > mill && chmod +x mill

cat > build.sc <<EOF
import mill._
import mill.scalalib._

object project extends ScalaModule {
  override def scalaVersion = "2.13.15"

  object test extends Tests with TestModule.Munit {
    override def ivyDeps = Agg(ivy"org.scalameta::munit::1.0.4")
  }
}
EOF

cat > .mill-version <<EOF
0.10.15
EOF

mkdir -p project/test/src
cat > project/test/src/Test.scala <<EOF
class Test extends munit.FunSuite {
  test("Load resources") {
    assert(getClass.getResource(s"/somefile") != null, "Unable to find somefile in the resources")
  }
}
EOF

mkdir -p project/test/resources
cat > project/test/resources/somefile <<EOF
blablabla
EOF

@lefou lefou added the bug The issue represents an bug label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue represents an bug
Projects
None yet
Development

No branches or pull requests

2 participants