From 4ee79596dc7f824cf93f105240ab7bc4c99a7eaf Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 26 Jan 2024 09:18:30 +0800 Subject: [PATCH] . --- build.sc | 2 +- mainargs/test/src/TraitTests.scala | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 mainargs/test/src/TraitTests.scala diff --git a/build.sc b/build.sc index 20eb74b..3bb1331 100644 --- a/build.sc +++ b/build.sc @@ -8,7 +8,7 @@ import com.github.lolgab.mill.mima._ val scala212 = "2.12.17" val scala213 = "2.13.10" -val scala3 = "3.1.3" +val scala3 = "3.3.1" val osLib = "0.9.1" val acyclic = "0.3.9" diff --git a/mainargs/test/src/TraitTests.scala b/mainargs/test/src/TraitTests.scala new file mode 100644 index 0000000..a9842c3 --- /dev/null +++ b/mainargs/test/src/TraitTests.scala @@ -0,0 +1,26 @@ +package mainargs +import utest._ + +object TraitTests extends TestSuite { + + trait CommandList { + @main + def list(@arg v: String) = v + } + + trait CommandCopy { + @main + def copy(@arg from: String, @arg to: String) = (from, to) + } + + object Main extends CommandList with CommandCopy { + def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) + } + + val tests = Tests { + test("explicit") { + ParserForMethods(Main).runOrThrow(Array("list", "-v", "hello")) ==> "hello" + ParserForMethods(Main).runOrThrow(Array("copy", "--from", "hello", "--to", "world")) ==> ("hello", "world") + } + } +}