Skip to content

Commit 7a50b88

Browse files
committed
add examples and adocs
1 parent e156bc1 commit 7a50b88

File tree

18 files changed

+339
-22
lines changed

18 files changed

+339
-22
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// SNIPPET:BUILD1
2+
package build
3+
import mill._, javalib._
4+
import os._
5+
6+
object foo extends JavaModule {
7+
object test extends JavaTests {
8+
def testFramework = "com.novocode.junit.JUnitFramework" // Use JUnit 4 framework interface
9+
def mvnDeps = Seq(
10+
mvn"junit:junit:4.13.2", // JUnit 4 itself
11+
mvn"com.novocode:junit-interface:0.11" // sbt-compatible JUnit interface
12+
)
13+
}
14+
// Ultilities for replacing text in files
15+
def replaceBar(args: String*) = Task.Command {
16+
val relativePath = os.RelPath("../../../foo/src/Bar.java")
17+
val filePath = Task.dest() / relativePath
18+
os.write.over(filePath, os.read(filePath).replace(
19+
"""return String.format("Hi, %s!", name);""",
20+
"""return String.format("Ciao, %s!", name);"""
21+
))
22+
}
23+
24+
def replaceFooTest2(args: String*) = Task.Command {
25+
val relativePath = os.RelPath("../../../foo/test/src/FooTest2.java")
26+
val filePath = Task.dest() / relativePath
27+
os.write.over(filePath, os.read(filePath).replace(
28+
"""assertEquals("Hi, " + name + "!", greeted);""",
29+
"""assertEquals("Ciao, " + name + "!", greeted);""",
30+
))
31+
}
32+
}
33+
//// SNIPPET:END
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package foo;
2+
3+
public class Bar {
4+
public static String greet(String name) {
5+
return String.format("Hello, %s!", name);
6+
}
7+
8+
public static String greet2(String name) {
9+
return String.format("Hi, %s!", name);
10+
}
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package foo;
2+
3+
public class Foo {
4+
public static void main(String[] args) {
5+
System.out.println(Bar.greet("World"));
6+
}
7+
8+
public static String greet(String name) {
9+
return Bar.greet(name);
10+
}
11+
12+
public static String greet2(String name) {
13+
return Bar.greet2(name);
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package foo;
2+
3+
import org.junit.Test;
4+
import static org.junit.Assert.*;
5+
6+
public class FooTest1 {
7+
@Test
8+
public void test1() {
9+
String name = "Aether";
10+
String greeted = Foo.greet(name);
11+
assertEquals("Hello, " + name + "!", greeted);
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package foo;
2+
3+
import org.junit.Test;
4+
import static org.junit.Assert.*;
5+
6+
public class FooTest2 {
7+
@Test
8+
public void test2() {
9+
String name = "Bob";
10+
String greeted = Foo.greet2(name);
11+
assertEquals("Hi, " + name + "!", greeted);
12+
}
13+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// SNIPPET:BUILD1
2+
package build
3+
import mill._, kotlinlib._
4+
import os._
5+
6+
object foo extends KotlinModule {
7+
def kotlinVersion = "1.9.24" // Specify your Kotlin version
8+
9+
object test extends KotlinTests {
10+
def testFramework = "com.github.sbt.junit.jupiter.api.JupiterFramework" // Use JUnit 5 framework
11+
def mvnDeps = Seq(
12+
// JUnit 5 dependencies
13+
mvn"org.junit.jupiter:junit-jupiter-api:5.10.0",
14+
mvn"org.junit.jupiter:junit-jupiter-engine:5.10.0",
15+
// Test runner interface for Mill/sbt
16+
mvn"com.github.sbt.junit:jupiter-interface:0.13.3"
17+
)
18+
}
19+
20+
def replaceBar(args: String*) = Task.Command {
21+
val relativePath = os.RelPath("../../../foo/src/Bar.kt")
22+
val filePath = T.dest / relativePath
23+
os.write.over(filePath, os.read(filePath).replace(
24+
"""return "Hi, $name!"""",
25+
"""return "Ciao, $name!""""
26+
))
27+
}
28+
29+
def replaceFooTest2(args: String*) = Task.Command {
30+
val relativePath = os.RelPath("../../../foo/test/src/FooTest2.kt")
31+
val filePath = T.dest / relativePath
32+
os.write.over(filePath, os.read(filePath).replace(
33+
"""assertEquals("Hi, $name!", greeted)""",
34+
"""assertEquals("Ciao, $name!", greeted)"""
35+
))
36+
}
37+
}
38+
//// SNIPPET:END
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package foo
2+
3+
object Bar {
4+
fun greet(name: String): String {
5+
return "Hello, $name!"
6+
}
7+
8+
fun greet2(name: String): String {
9+
return "Hi, $name!"
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package foo
2+
3+
object Foo {
4+
@JvmStatic
5+
fun main(args: Array<String>) {
6+
println(Bar.greet("World"))
7+
}
8+
9+
fun greet(name: String): String {
10+
return Bar.greet(name)
11+
}
12+
13+
fun greet2(name: String): String {
14+
return Bar.greet2(name)
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package foo
2+
3+
import org.junit.jupiter.api.Test
4+
import org.junit.jupiter.api.Assertions.*
5+
6+
class FooTest1 {
7+
@Test
8+
fun test1() {
9+
val name = "Aether"
10+
val greeted = Foo.greet(name)
11+
assertEquals("Hello, $name!", greeted)
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package foo
2+
3+
import org.junit.jupiter.api.Test
4+
import org.junit.jupiter.api.Assertions.*
5+
6+
class FooTest2 {
7+
@Test
8+
fun test2() {
9+
val name = "Bob"
10+
val greeted = Foo.greet2(name)
11+
assertEquals("Hi, $name!", greeted)
12+
}
13+
}

0 commit comments

Comments
 (0)