goscript 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/README.md +267 -255
  2. package/cmd/goscript/cmd-test.go +193 -0
  3. package/cmd/goscript/cmd-test_test.go +76 -0
  4. package/cmd/goscript/main.go +1 -0
  5. package/compiler/build-flags.go +38 -0
  6. package/compiler/compile-request.go +2 -0
  7. package/compiler/compliance_test.go +0 -8
  8. package/compiler/gotest/owner.go +24 -0
  9. package/compiler/gotest/package-result.go +67 -0
  10. package/compiler/gotest/request.go +145 -0
  11. package/compiler/gotest/result.go +28 -0
  12. package/compiler/gotest/runner.go +588 -0
  13. package/compiler/gotest/runner_test.go +627 -0
  14. package/compiler/gotest/test.go +9 -0
  15. package/compiler/index.test.ts +1 -1
  16. package/compiler/lowered-program.go +71 -19
  17. package/compiler/lowering.go +5065 -569
  18. package/compiler/override-facts.go +307 -0
  19. package/compiler/override-registry.go +50 -189
  20. package/compiler/override-registry_test.go +47 -0
  21. package/compiler/package-graph.go +50 -27
  22. package/compiler/package-graph_test.go +37 -2
  23. package/compiler/package-test-function.go +9 -0
  24. package/compiler/package-test-graph-package.go +40 -0
  25. package/compiler/package-test-graph-variant.go +105 -0
  26. package/compiler/package-test-graph.go +117 -0
  27. package/compiler/package-test-graph_test.go +144 -0
  28. package/compiler/runtime-contract.go +189 -29
  29. package/compiler/runtime-contract_test.go +44 -30
  30. package/compiler/semantic-model-types.go +9 -6
  31. package/compiler/semantic-model.go +538 -38
  32. package/compiler/semantic-model_test.go +55 -0
  33. package/compiler/service.go +1 -1
  34. package/compiler/skeleton_test.go +679 -49
  35. package/compiler/tsworkspace/owner.go +334 -0
  36. package/compiler/tsworkspace/owner_test.go +93 -0
  37. package/compiler/tsworkspace/result.go +17 -0
  38. package/compiler/typescript-emitter.go +459 -82
  39. package/compiler/wasm/compile.go +1 -1
  40. package/compiler/wasm/compile_test.go +61 -11
  41. package/compiler/wasm_api.go +172 -7
  42. package/dist/gs/builtin/builtin.d.ts +20 -2
  43. package/dist/gs/builtin/builtin.js +194 -6
  44. package/dist/gs/builtin/builtin.js.map +1 -1
  45. package/dist/gs/builtin/channel.d.ts +8 -0
  46. package/dist/gs/builtin/channel.js +12 -0
  47. package/dist/gs/builtin/channel.js.map +1 -1
  48. package/dist/gs/builtin/slice.d.ts +22 -2
  49. package/dist/gs/builtin/slice.js +216 -44
  50. package/dist/gs/builtin/slice.js.map +1 -1
  51. package/dist/gs/builtin/type.d.ts +5 -2
  52. package/dist/gs/builtin/type.js +83 -24
  53. package/dist/gs/builtin/type.js.map +1 -1
  54. package/dist/gs/builtin/varRef.d.ts +5 -0
  55. package/dist/gs/builtin/varRef.js +23 -0
  56. package/dist/gs/builtin/varRef.js.map +1 -1
  57. package/dist/gs/bytes/buffer.gs.js +48 -44
  58. package/dist/gs/bytes/buffer.gs.js.map +1 -1
  59. package/dist/gs/bytes/reader.gs.js +20 -18
  60. package/dist/gs/bytes/reader.gs.js.map +1 -1
  61. package/dist/gs/context/context.d.ts +5 -4
  62. package/dist/gs/context/context.js +10 -10
  63. package/dist/gs/context/context.js.map +1 -1
  64. package/dist/gs/crypto/internal/fips140deps/byteorder/index.d.ts +1 -0
  65. package/dist/gs/crypto/internal/fips140deps/byteorder/index.js +2 -0
  66. package/dist/gs/crypto/internal/fips140deps/byteorder/index.js.map +1 -0
  67. package/dist/gs/crypto/internal/fips140deps/godebug/index.d.ts +1 -0
  68. package/dist/gs/crypto/internal/fips140deps/godebug/index.js +2 -0
  69. package/dist/gs/crypto/internal/fips140deps/godebug/index.js.map +1 -0
  70. package/dist/gs/embed/index.d.ts +7 -0
  71. package/dist/gs/embed/index.js +16 -0
  72. package/dist/gs/embed/index.js.map +1 -0
  73. package/dist/gs/encoding/json/index.d.ts +1 -0
  74. package/dist/gs/encoding/json/index.js +18 -0
  75. package/dist/gs/encoding/json/index.js.map +1 -1
  76. package/dist/gs/errors/errors.d.ts +4 -0
  77. package/dist/gs/errors/errors.js +81 -0
  78. package/dist/gs/errors/errors.js.map +1 -1
  79. package/dist/gs/fmt/fmt.d.ts +4 -4
  80. package/dist/gs/fmt/fmt.js +42 -11
  81. package/dist/gs/fmt/fmt.js.map +1 -1
  82. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +35 -0
  83. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +211 -1
  84. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
  85. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.d.ts +189 -0
  86. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +825 -0
  87. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -0
  88. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +163 -0
  89. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +449 -0
  90. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -0
  91. package/dist/gs/github.com/klauspost/compress/internal/le/index.d.ts +9 -0
  92. package/dist/gs/github.com/klauspost/compress/internal/le/index.js +71 -0
  93. package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -0
  94. package/dist/gs/go/internal/scannerhooks/index.d.ts +3 -0
  95. package/dist/gs/go/internal/scannerhooks/index.js +5 -0
  96. package/dist/gs/go/internal/scannerhooks/index.js.map +1 -0
  97. package/dist/gs/go/scanner/index.d.ts +13 -0
  98. package/dist/gs/go/scanner/index.js +35 -0
  99. package/dist/gs/go/scanner/index.js.map +1 -1
  100. package/dist/gs/go/token/index.d.ts +156 -0
  101. package/dist/gs/go/token/index.js +500 -4
  102. package/dist/gs/go/token/index.js.map +1 -1
  103. package/dist/gs/internal/abi/index.d.ts +4 -0
  104. package/dist/gs/internal/abi/index.js +10 -0
  105. package/dist/gs/internal/abi/index.js.map +1 -1
  106. package/dist/gs/internal/bytealg/index.d.ts +2 -0
  107. package/dist/gs/internal/bytealg/index.js +14 -0
  108. package/dist/gs/internal/bytealg/index.js.map +1 -1
  109. package/dist/gs/internal/byteorder/index.d.ts +8 -2
  110. package/dist/gs/internal/byteorder/index.js +56 -25
  111. package/dist/gs/internal/byteorder/index.js.map +1 -1
  112. package/dist/gs/internal/godebug/index.d.ts +12 -0
  113. package/dist/gs/internal/godebug/index.js +30 -0
  114. package/dist/gs/internal/godebug/index.js.map +1 -0
  115. package/dist/gs/io/fs/index.d.ts +1 -0
  116. package/dist/gs/io/fs/index.js +1 -0
  117. package/dist/gs/io/fs/index.js.map +1 -1
  118. package/dist/gs/io/fs/readlink.d.ts +8 -0
  119. package/dist/gs/io/fs/readlink.js +64 -0
  120. package/dist/gs/io/fs/readlink.js.map +1 -0
  121. package/dist/gs/io/fs/walk.d.ts +3 -3
  122. package/dist/gs/io/fs/walk.js +7 -7
  123. package/dist/gs/io/fs/walk.js.map +1 -1
  124. package/dist/gs/io/io.d.ts +40 -6
  125. package/dist/gs/io/io.js +151 -26
  126. package/dist/gs/io/io.js.map +1 -1
  127. package/dist/gs/maps/iter.d.ts +3 -3
  128. package/dist/gs/maps/iter.js +3 -3
  129. package/dist/gs/maps/iter.js.map +1 -1
  130. package/dist/gs/maps/maps.d.ts +2 -2
  131. package/dist/gs/maps/maps.js +1 -1
  132. package/dist/gs/maps/maps.js.map +1 -1
  133. package/dist/gs/math/bits/index.d.ts +13 -4
  134. package/dist/gs/math/bits/index.js +66 -34
  135. package/dist/gs/math/bits/index.js.map +1 -1
  136. package/dist/gs/math/const.gs.d.ts +5 -5
  137. package/dist/gs/math/const.gs.js +4 -4
  138. package/dist/gs/math/const.gs.js.map +1 -1
  139. package/dist/gs/mime/index.d.ts +1 -0
  140. package/dist/gs/mime/index.js +50 -0
  141. package/dist/gs/mime/index.js.map +1 -0
  142. package/dist/gs/net/http/httptest/index.d.ts +11 -0
  143. package/dist/gs/net/http/httptest/index.js +21 -0
  144. package/dist/gs/net/http/httptest/index.js.map +1 -0
  145. package/dist/gs/net/http/index.d.ts +27 -0
  146. package/dist/gs/net/http/index.js +61 -0
  147. package/dist/gs/net/http/index.js.map +1 -0
  148. package/dist/gs/os/dir_unix.gs.js +2 -2
  149. package/dist/gs/os/dir_unix.gs.js.map +1 -1
  150. package/dist/gs/os/types_js.gs.js.map +1 -1
  151. package/dist/gs/path/filepath/match.js +165 -3
  152. package/dist/gs/path/filepath/match.js.map +1 -1
  153. package/dist/gs/path/filepath/path.d.ts +3 -1
  154. package/dist/gs/path/filepath/path.js +133 -4
  155. package/dist/gs/path/filepath/path.js.map +1 -1
  156. package/dist/gs/path/path.d.ts +4 -1
  157. package/dist/gs/path/path.js +16 -4
  158. package/dist/gs/path/path.js.map +1 -1
  159. package/dist/gs/reflect/index.d.ts +1 -1
  160. package/dist/gs/reflect/index.js +1 -1
  161. package/dist/gs/reflect/index.js.map +1 -1
  162. package/dist/gs/reflect/map.js +3 -0
  163. package/dist/gs/reflect/map.js.map +1 -1
  164. package/dist/gs/reflect/type.d.ts +7 -4
  165. package/dist/gs/reflect/type.js +148 -7
  166. package/dist/gs/reflect/type.js.map +1 -1
  167. package/dist/gs/runtime/debug/index.d.ts +2 -0
  168. package/dist/gs/runtime/debug/index.js +8 -0
  169. package/dist/gs/runtime/debug/index.js.map +1 -0
  170. package/dist/gs/runtime/runtime.d.ts +35 -3
  171. package/dist/gs/runtime/runtime.js +72 -0
  172. package/dist/gs/runtime/runtime.js.map +1 -1
  173. package/dist/gs/slices/slices.d.ts +24 -5
  174. package/dist/gs/slices/slices.js +214 -5
  175. package/dist/gs/slices/slices.js.map +1 -1
  176. package/dist/gs/sort/slice.gs.d.ts +3 -3
  177. package/dist/gs/sort/slice.gs.js +6 -6
  178. package/dist/gs/sort/slice.gs.js.map +1 -1
  179. package/dist/gs/sort/sort.gs.d.ts +4 -4
  180. package/dist/gs/sort/sort.gs.js +11 -8
  181. package/dist/gs/sort/sort.gs.js.map +1 -1
  182. package/dist/gs/strings/builder.d.ts +1 -1
  183. package/dist/gs/strings/builder.js +3 -2
  184. package/dist/gs/strings/builder.js.map +1 -1
  185. package/dist/gs/sync/atomic/type.gs.d.ts +9 -8
  186. package/dist/gs/sync/atomic/type.gs.js +0 -2
  187. package/dist/gs/sync/atomic/type.gs.js.map +1 -1
  188. package/dist/gs/sync/sync.d.ts +2 -0
  189. package/dist/gs/sync/sync.js +27 -0
  190. package/dist/gs/sync/sync.js.map +1 -1
  191. package/dist/gs/syscall/constants.d.ts +36 -24
  192. package/dist/gs/syscall/constants.js +12 -0
  193. package/dist/gs/syscall/constants.js.map +1 -1
  194. package/dist/gs/syscall/errors.d.ts +2 -0
  195. package/dist/gs/syscall/errors.js +8 -0
  196. package/dist/gs/syscall/errors.js.map +1 -1
  197. package/dist/gs/syscall/fs.d.ts +43 -0
  198. package/dist/gs/syscall/fs.js +102 -0
  199. package/dist/gs/syscall/fs.js.map +1 -1
  200. package/dist/gs/syscall/js/index.d.ts +90 -0
  201. package/dist/gs/syscall/js/index.js +375 -0
  202. package/dist/gs/syscall/js/index.js.map +1 -0
  203. package/dist/gs/syscall/types.d.ts +22 -0
  204. package/dist/gs/syscall/types.js +45 -1
  205. package/dist/gs/syscall/types.js.map +1 -1
  206. package/dist/gs/testing/index.d.ts +1 -0
  207. package/dist/gs/testing/index.js +2 -0
  208. package/dist/gs/testing/index.js.map +1 -0
  209. package/dist/gs/testing/testing.d.ts +77 -0
  210. package/dist/gs/testing/testing.js +301 -0
  211. package/dist/gs/testing/testing.js.map +1 -0
  212. package/dist/gs/time/time.d.ts +41 -4
  213. package/dist/gs/time/time.js +205 -36
  214. package/dist/gs/time/time.js.map +1 -1
  215. package/dist/gs/unicode/unicode.d.ts +23 -1
  216. package/dist/gs/unicode/unicode.js +79 -10
  217. package/dist/gs/unicode/unicode.js.map +1 -1
  218. package/dist/gs/unicode/utf8/utf8.d.ts +4 -4
  219. package/dist/gs/unicode/utf8/utf8.js +24 -11
  220. package/dist/gs/unicode/utf8/utf8.js.map +1 -1
  221. package/dist/gs/unique/index.d.ts +11 -0
  222. package/dist/gs/unique/index.js +71 -0
  223. package/dist/gs/unique/index.js.map +1 -0
  224. package/go.sum +9 -0
  225. package/gs/builtin/builtin.ts +239 -8
  226. package/gs/builtin/channel.ts +22 -0
  227. package/gs/builtin/runtime-contract.test.ts +126 -0
  228. package/gs/builtin/slice.ts +259 -50
  229. package/gs/builtin/type.ts +109 -34
  230. package/gs/builtin/varRef.ts +38 -1
  231. package/gs/bytes/buffer.gs.ts +48 -44
  232. package/gs/bytes/meta.json +8 -3
  233. package/gs/bytes/reader.gs.ts +20 -19
  234. package/gs/context/context.test.ts +41 -0
  235. package/gs/context/context.ts +22 -26
  236. package/gs/crypto/internal/fips140deps/byteorder/index.ts +1 -0
  237. package/gs/crypto/internal/fips140deps/godebug/index.ts +1 -0
  238. package/gs/embed/index.ts +20 -0
  239. package/gs/embed/meta.json +5 -0
  240. package/gs/encoding/json/index.test.ts +15 -1
  241. package/gs/encoding/json/index.ts +24 -0
  242. package/gs/errors/errors.test.ts +82 -0
  243. package/gs/errors/errors.ts +104 -0
  244. package/gs/fmt/fmt.ts +56 -16
  245. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +73 -1
  246. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +297 -1
  247. package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +159 -0
  248. package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +1005 -0
  249. package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +719 -0
  250. package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +40 -0
  251. package/gs/github.com/klauspost/compress/internal/le/index.test.ts +36 -0
  252. package/gs/github.com/klauspost/compress/internal/le/index.ts +114 -0
  253. package/gs/go/internal/scannerhooks/index.test.ts +14 -0
  254. package/gs/go/internal/scannerhooks/index.ts +9 -0
  255. package/gs/go/scanner/index.test.ts +22 -0
  256. package/gs/go/scanner/index.ts +47 -0
  257. package/gs/go/token/index.test.ts +47 -1
  258. package/gs/go/token/index.ts +570 -4
  259. package/gs/internal/abi/index.test.ts +18 -0
  260. package/gs/internal/abi/index.ts +14 -0
  261. package/gs/internal/bytealg/index.test.ts +18 -0
  262. package/gs/internal/bytealg/index.ts +16 -0
  263. package/gs/internal/byteorder/index.test.ts +39 -0
  264. package/gs/internal/byteorder/index.ts +100 -27
  265. package/gs/internal/godebug/index.test.ts +16 -0
  266. package/gs/internal/godebug/index.ts +35 -0
  267. package/gs/io/fs/index.ts +1 -0
  268. package/gs/io/fs/meta.json +5 -0
  269. package/gs/io/fs/readlink.test.ts +43 -0
  270. package/gs/io/fs/readlink.ts +77 -0
  271. package/gs/io/fs/walk.test.ts +61 -0
  272. package/gs/io/fs/walk.ts +9 -9
  273. package/gs/io/io.ts +174 -31
  274. package/gs/io/meta.json +10 -2
  275. package/gs/maps/iter.ts +12 -6
  276. package/gs/maps/maps.ts +8 -6
  277. package/gs/math/bits/index.ts +103 -47
  278. package/gs/math/const.gs.test.ts +11 -5
  279. package/gs/math/const.gs.ts +5 -6
  280. package/gs/mime/index.ts +54 -0
  281. package/gs/net/http/httptest/index.ts +25 -0
  282. package/gs/net/http/index.test.ts +20 -0
  283. package/gs/net/http/index.ts +81 -0
  284. package/gs/os/dir_unix.gs.ts +2 -3
  285. package/gs/os/types_js.gs.ts +2 -2
  286. package/gs/path/filepath/match.test.ts +31 -12
  287. package/gs/path/filepath/match.ts +178 -3
  288. package/gs/path/filepath/path.test.ts +25 -0
  289. package/gs/path/filepath/path.ts +159 -5
  290. package/gs/path/path.ts +20 -5
  291. package/gs/reflect/index.ts +1 -0
  292. package/gs/reflect/map.test.ts +19 -0
  293. package/gs/reflect/map.ts +4 -0
  294. package/gs/reflect/type.ts +197 -17
  295. package/gs/runtime/debug/index.test.ts +24 -0
  296. package/gs/runtime/debug/index.ts +8 -0
  297. package/gs/runtime/runtime.test.ts +19 -0
  298. package/gs/runtime/runtime.ts +98 -3
  299. package/gs/slices/slices.test.ts +94 -0
  300. package/gs/slices/slices.ts +245 -5
  301. package/gs/sort/meta.json +7 -0
  302. package/gs/sort/slice.gs.ts +16 -7
  303. package/gs/sort/sort.gs.ts +16 -13
  304. package/gs/strings/builder.ts +4 -3
  305. package/gs/sync/atomic/type.gs.ts +13 -14
  306. package/gs/sync/meta.json +3 -1
  307. package/gs/sync/sync.test.ts +13 -1
  308. package/gs/sync/sync.ts +27 -0
  309. package/gs/syscall/constants.ts +39 -24
  310. package/gs/syscall/errors.ts +10 -0
  311. package/gs/syscall/fs.ts +195 -0
  312. package/gs/syscall/js/index.ts +458 -0
  313. package/gs/syscall/js/meta.json +4 -0
  314. package/gs/syscall/net.test.ts +85 -0
  315. package/gs/syscall/types.ts +56 -0
  316. package/gs/testing/index.ts +1 -0
  317. package/gs/testing/meta.json +5 -0
  318. package/gs/testing/testing.test.ts +90 -0
  319. package/gs/testing/testing.ts +382 -0
  320. package/gs/time/time.test.ts +106 -0
  321. package/gs/time/time.ts +278 -57
  322. package/gs/unicode/unicode.test.ts +25 -0
  323. package/gs/unicode/unicode.ts +119 -9
  324. package/gs/unicode/utf8/utf8.test.ts +13 -0
  325. package/gs/unicode/utf8/utf8.ts +28 -16
  326. package/gs/unique/index.ts +91 -0
  327. package/package.json +2 -1
@@ -0,0 +1,193 @@
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "io"
6
+ "strconv"
7
+ "strings"
8
+ "time"
9
+
10
+ "github.com/aperturerobotics/cli"
11
+ "github.com/aperturerobotics/goscript/compiler/gotest"
12
+ "github.com/pkg/errors"
13
+ )
14
+
15
+ func testCommands() []*cli.Command {
16
+ return []*cli.Command{newTestCommand()}
17
+ }
18
+
19
+ func newTestCommand() *cli.Command {
20
+ var tags cli.StringSlice
21
+ var run string
22
+ var count int
23
+ var short bool
24
+ var timeout time.Duration
25
+ var verbose bool
26
+ var outputRoot string
27
+ var workDir string
28
+ var dir string
29
+
30
+ return &cli.Command{
31
+ Name: "test",
32
+ Category: "test",
33
+ Usage: "compile and run Go package tests through GoScript",
34
+ Action: func(c *cli.Context) error {
35
+ req := &gotest.Request{
36
+ Dir: dir,
37
+ Patterns: c.Args().Slice(),
38
+ BuildTags: tags.Value(),
39
+ Run: run,
40
+ Count: count,
41
+ Short: short,
42
+ Timeout: timeout,
43
+ Verbose: verbose,
44
+ WorkDir: workDir,
45
+ OutputRoot: outputRoot,
46
+ }
47
+ result, err := gotest.NewRunner().Run(c.Context, req)
48
+ if err != nil {
49
+ return err
50
+ }
51
+ if err := printTestResult(c.Context, c.App.Writer, result); err != nil {
52
+ return err
53
+ }
54
+ if !result.Passed() {
55
+ return errors.New("goscript test failed")
56
+ }
57
+ return nil
58
+ },
59
+ Flags: []cli.Flag{
60
+ &cli.StringSliceFlag{
61
+ Name: "tags",
62
+ Usage: "comma-separated Go build tags",
63
+ Destination: &tags,
64
+ },
65
+ &cli.StringFlag{
66
+ Name: "run",
67
+ Usage: "run only tests matching the regexp",
68
+ Destination: &run,
69
+ },
70
+ &cli.IntFlag{
71
+ Name: "count",
72
+ Usage: "run each selected test this many times",
73
+ Destination: &count,
74
+ Value: 1,
75
+ },
76
+ &cli.BoolFlag{
77
+ Name: "short",
78
+ Usage: "report true from testing.Short",
79
+ Destination: &short,
80
+ },
81
+ &cli.DurationFlag{
82
+ Name: "timeout",
83
+ Usage: "maximum time for the package-test run",
84
+ Destination: &timeout,
85
+ Value: 30 * time.Second,
86
+ },
87
+ &cli.BoolFlag{
88
+ Name: "v",
89
+ Aliases: []string{"verbose"},
90
+ Usage: "emit verbose test output",
91
+ Destination: &verbose,
92
+ },
93
+ &cli.StringFlag{
94
+ Name: "output",
95
+ Usage: "generated TypeScript output root",
96
+ Destination: &outputRoot,
97
+ },
98
+ &cli.StringFlag{
99
+ Name: "workdir",
100
+ Usage: "generated test workspace directory",
101
+ Destination: &workDir,
102
+ },
103
+ &cli.StringFlag{
104
+ Name: "dir",
105
+ Usage: "Go module working directory",
106
+ Destination: &dir,
107
+ },
108
+ },
109
+ }
110
+ }
111
+
112
+ func printTestResult(ctx context.Context, w io.Writer, result *gotest.Result) error {
113
+ if err := ctx.Err(); err != nil {
114
+ return err
115
+ }
116
+ if result == nil {
117
+ return errors.New("goscript test result is nil")
118
+ }
119
+ for _, pkg := range result.Packages {
120
+ if strings.TrimSpace(pkg.Output) != "" {
121
+ if _, err := io.WriteString(w, strings.TrimSpace(pkg.Output)+"\n"); err != nil {
122
+ return err
123
+ }
124
+ }
125
+ switch pkg.Action {
126
+ case gotest.ActionPass:
127
+ if _, err := io.WriteString(w, "ok \t"+pkg.PackagePath+"\t"+formatElapsed(pkg.Elapsed)+"\n"); err != nil {
128
+ return err
129
+ }
130
+ case gotest.ActionSkip:
131
+ if _, err := io.WriteString(w, "? \t"+pkg.PackagePath+"\t[no test files]\n"); err != nil {
132
+ return err
133
+ }
134
+ case gotest.ActionFail:
135
+ line := "FAIL\t" + pkg.PackagePath
136
+ if pkg.Owner != "" {
137
+ line += "\towner=" + string(pkg.Owner)
138
+ }
139
+ if phase := failedPhase(pkg.Phases); phase != "" {
140
+ line += "\tphase=" + phase
141
+ }
142
+ if _, err := io.WriteString(w, line+"\n"); err != nil {
143
+ return err
144
+ }
145
+ if strings.TrimSpace(pkg.Error) != "" {
146
+ if _, err := io.WriteString(w, strings.TrimSpace(pkg.Error)+"\n"); err != nil {
147
+ return err
148
+ }
149
+ }
150
+ }
151
+ }
152
+ if result.WorkDir != "" {
153
+ if _, err := io.WriteString(w, "goscript test workdir: "+result.WorkDir+"\n"); err != nil {
154
+ return err
155
+ }
156
+ }
157
+ return nil
158
+ }
159
+
160
+ func failedPhase(phases gotest.PackagePhases) string {
161
+ switch {
162
+ case phases.Workspace == gotest.PhaseStatusFail:
163
+ return "workspace"
164
+ case phases.Compile == gotest.PhaseStatusFail:
165
+ return "compile"
166
+ case phases.Emit == gotest.PhaseStatusFail:
167
+ return "emit"
168
+ case phases.TypeCheck == gotest.PhaseStatusFail:
169
+ return "typecheck"
170
+ case phases.Runtime == gotest.PhaseStatusFail:
171
+ return "runtime"
172
+ default:
173
+ return ""
174
+ }
175
+ }
176
+
177
+ func formatElapsed(elapsed time.Duration) string {
178
+ if elapsed <= 0 {
179
+ return "0.000s"
180
+ }
181
+ millis := elapsed.Milliseconds()
182
+ seconds := millis / 1000
183
+ remainder := millis % 1000
184
+ return strconv.FormatInt(seconds, 10) + "." + leftPadMillis(remainder) + "s"
185
+ }
186
+
187
+ func leftPadMillis(value int64) string {
188
+ raw := strconv.FormatInt(value, 10)
189
+ for len(raw) < 3 {
190
+ raw = "0" + raw
191
+ }
192
+ return raw
193
+ }
@@ -0,0 +1,76 @@
1
+ package main
2
+
3
+ import (
4
+ "bytes"
5
+ "path/filepath"
6
+ "strings"
7
+ "testing"
8
+ )
9
+
10
+ func TestTestCommandHelp(t *testing.T) {
11
+ var out bytes.Buffer
12
+ app := newApp()
13
+ app.Writer = &out
14
+
15
+ err := app.Run([]string{"goscript", "test", "--help"})
16
+ if err != nil {
17
+ t.Fatalf("test help failed: %v", err)
18
+ }
19
+ help := out.String()
20
+ for _, expected := range []string{"compile and run Go package tests through GoScript", "--tags", "--run", "--count", "--short", "--timeout"} {
21
+ if !strings.Contains(help, expected) {
22
+ t.Fatalf("help output missing %q:\n%s", expected, help)
23
+ }
24
+ }
25
+ }
26
+
27
+ func TestTestCommandRunsPackageTest(t *testing.T) {
28
+ dir := t.TempDir()
29
+ writeFile(t, filepath.Join(dir, "go.mod"), "module example.test/cmdtest\n\ngo 1.25.3\n")
30
+ writeFile(t, filepath.Join(dir, "value.go"), strings.Join([]string{
31
+ "package cmdtest",
32
+ "func Value() int { return 7 }",
33
+ "",
34
+ }, "\n"))
35
+ writeFile(t, filepath.Join(dir, "value_test.go"), strings.Join([]string{
36
+ "package cmdtest",
37
+ "import \"testing\"",
38
+ "func TestValue(t *testing.T) {",
39
+ "\tif Value() != 7 {",
40
+ "\t\tt.Fatal(\"bad value\")",
41
+ "\t}",
42
+ "}",
43
+ "",
44
+ }, "\n"))
45
+
46
+ var out bytes.Buffer
47
+ app := newApp()
48
+ app.Writer = &out
49
+ err := app.Run([]string{
50
+ "goscript",
51
+ "test",
52
+ "--dir",
53
+ dir,
54
+ "--workdir",
55
+ filepath.Join(dir, ".tmp", "cmd-test"),
56
+ "-v",
57
+ ".",
58
+ })
59
+ if err != nil {
60
+ t.Fatalf("test command failed: %v\n%s", err, out.String())
61
+ }
62
+ if !strings.Contains(out.String(), "ok \texample.test/cmdtest") {
63
+ t.Fatalf("expected ok package output, got:\n%s", out.String())
64
+ }
65
+ }
66
+
67
+ func TestTestCommandRejectsUnsupportedFlags(t *testing.T) {
68
+ app := newApp()
69
+ err := app.Run([]string{"goscript", "test", "--cover", "."})
70
+ if err == nil {
71
+ t.Fatalf("expected unsupported flag to fail")
72
+ }
73
+ if !strings.Contains(err.Error(), "flag provided but not defined") {
74
+ t.Fatalf("unexpected unsupported flag error: %v", err)
75
+ }
76
+ }
@@ -27,6 +27,7 @@ func newApp() *cli.App {
27
27
 
28
28
  app.Usage = "GoScript compiles Go to Typescript."
29
29
  app.Commands = append(app.Commands, compileCommands()...)
30
+ app.Commands = append(app.Commands, testCommands()...)
30
31
 
31
32
  return app
32
33
  }
@@ -0,0 +1,38 @@
1
+ package compiler
2
+
3
+ import "slices"
4
+
5
+ import "strings"
6
+
7
+ const goScriptBuildTag = "goscript"
8
+
9
+ func goScriptBuildFlags(flags []string) []string {
10
+ normalized := append([]string(nil), flags...)
11
+ for i, flag := range normalized {
12
+ switch {
13
+ case flag == "-tags" && i+1 < len(normalized):
14
+ normalized[i+1] = appendBuildTag(normalized[i+1], goScriptBuildTag)
15
+ return normalized
16
+ case strings.HasPrefix(flag, "-tags="):
17
+ normalized[i] = "-tags=" + appendBuildTag(strings.TrimPrefix(flag, "-tags="), goScriptBuildTag)
18
+ return normalized
19
+ }
20
+ }
21
+ return append(normalized, "-tags="+goScriptBuildTag)
22
+ }
23
+
24
+ func appendBuildTag(value string, tag string) string {
25
+ tags := strings.FieldsFunc(value, func(r rune) bool {
26
+ return r == ',' || r == ' ' || r == '\t' || r == '\n'
27
+ })
28
+ if slices.Contains(tags, tag) {
29
+ return value
30
+ }
31
+ if strings.TrimSpace(value) == "" {
32
+ return tag
33
+ }
34
+ if strings.ContainsAny(value, " \t\n") {
35
+ return value + " " + tag
36
+ }
37
+ return value + "," + tag
38
+ }
@@ -40,6 +40,8 @@ type CompileRequest struct {
40
40
  DependencyMode DependencyMode
41
41
  // RuntimeEmissionMode controls runtime package emission policy.
42
42
  RuntimeEmissionMode RuntimeEmissionMode
43
+ // Tests controls whether package loading includes Go package-test variants.
44
+ Tests bool
43
45
  // AllDependencies controls whether the package graph should include deps.
44
46
  AllDependencies bool
45
47
  // DisableEmitBuiltin controls whether runtime packages are emitted.
@@ -125,14 +125,12 @@ var expectedV2ComplianceGaps = map[string]bool{
125
125
  "buffer_value_field_error": true,
126
126
  "bytes": true,
127
127
  "chan_type_assertion": true,
128
- "constants_iota": true,
129
128
  "debug_marshal": true,
130
129
  "debug_simple": true,
131
130
  "embedded_interface_null_assertion": true,
132
131
  "filepath_walkfunc_call": true,
133
132
  "flag_bitwise_op": true,
134
133
  "for_init_multi_assign": true,
135
- "for_post_multi_assign": true,
136
134
  "for_range": true,
137
135
  "function_call_variable_shadowing": true,
138
136
  "function_signature_type": true,
@@ -164,8 +162,6 @@ var expectedV2ComplianceGaps = map[string]bool{
164
162
  "method_receiver_with_call_expr": true,
165
163
  "missing_valueof_error": true,
166
164
  "multi_return_same_type": true,
167
- "named_return_method": true,
168
- "named_return_multiple": true,
169
165
  "named_slice_wrapper": true,
170
166
  "named_struct_async_method": true,
171
167
  "named_types_valueof": true,
@@ -175,22 +171,18 @@ var expectedV2ComplianceGaps = map[string]bool{
175
171
  "pointer_circular_ref": true,
176
172
  "pointer_composite_literal_untyped": true,
177
173
  "pointer_range_loop": true,
178
- "primitive_error_type": true,
179
174
  "promise_return_type": true,
180
175
  "protobuf_lite_ts": true,
181
- "range_const_reassign": true,
182
176
  "receiver_variable": true,
183
177
  "reflect_implements": true,
184
178
  "reflect_numfield": true,
185
179
  "reserved_words": true,
186
- "star_compound_assign": true,
187
180
  "star_expr_destructuring": true,
188
181
  "struct_embedding": true,
189
182
  "struct_embedding_bytes_buffer": true,
190
183
  "type_conversion_interface_ptr_nil": true,
191
184
  "type_declaration_receiver": true,
192
185
  "util_promise": true,
193
- "variable_shadowing_scope": true,
194
186
  "varref_deref_struct": true,
195
187
  "wrapper_type_args": true,
196
188
  }
@@ -0,0 +1,24 @@
1
+ // Package gotest owns GoScript package-test execution.
2
+ package gotest
3
+
4
+ // Owner classifies the package owner that should receive a test-runner failure.
5
+ type Owner string
6
+
7
+ const (
8
+ // OwnerPackageGraph classifies package pattern, build tag, or dependency graph failures.
9
+ OwnerPackageGraph Owner = "PackageGraphOwner"
10
+ // OwnerSemanticModel classifies Go type or semantic fact failures.
11
+ OwnerSemanticModel Owner = "SemanticModelOwner"
12
+ // OwnerLowering classifies unsupported Go-to-GoScript lowering failures.
13
+ OwnerLowering Owner = "LoweringOwner"
14
+ // OwnerTypeScriptEmitter classifies invalid emitted TypeScript failures.
15
+ OwnerTypeScriptEmitter Owner = "TypeScriptEmitterOwner"
16
+ // OwnerRuntimePackage classifies GoScript runtime primitive failures.
17
+ OwnerRuntimePackage Owner = "RuntimePackageOwner"
18
+ // OwnerOverridePackage classifies handwritten package override failures.
19
+ OwnerOverridePackage Owner = "OverridePackageOwner"
20
+ // OwnerTestRunner classifies generated testmain, execution, and aggregation failures.
21
+ OwnerTestRunner Owner = "TestRunnerOwner"
22
+ // OwnerSpacewaveHarness classifies target-ring or harness selection failures.
23
+ OwnerSpacewaveHarness Owner = "SpacewaveHarnessOwner"
24
+ )
@@ -0,0 +1,67 @@
1
+ package gotest
2
+
3
+ import "time"
4
+
5
+ // Action names the package-level result action.
6
+ type Action string
7
+
8
+ const (
9
+ // ActionPass means the package tests passed.
10
+ ActionPass Action = "pass"
11
+ // ActionFail means the package tests failed.
12
+ ActionFail Action = "fail"
13
+ // ActionSkip means the package has no runnable tests.
14
+ ActionSkip Action = "skip"
15
+ )
16
+
17
+ // PhaseStatus names a package-test phase state.
18
+ type PhaseStatus string
19
+
20
+ const (
21
+ // PhaseStatusPending means the phase has not run yet.
22
+ PhaseStatusPending PhaseStatus = "pending"
23
+ // PhaseStatusPass means the phase passed.
24
+ PhaseStatusPass PhaseStatus = "pass"
25
+ // PhaseStatusFail means the phase failed.
26
+ PhaseStatusFail PhaseStatus = "fail"
27
+ // PhaseStatusSkip means the phase was skipped.
28
+ PhaseStatusSkip PhaseStatus = "skip"
29
+ )
30
+
31
+ // PackagePhases records structured package-test phase status.
32
+ type PackagePhases struct {
33
+ // Workspace covers workspace files and tool discovery.
34
+ Workspace PhaseStatus
35
+ // Compile covers GoScript compile/lowering work.
36
+ Compile PhaseStatus
37
+ // Emit covers TypeScript emit/copy output work.
38
+ Emit PhaseStatus
39
+ // TypeCheck covers tsgo execution.
40
+ TypeCheck PhaseStatus
41
+ // Runtime covers Bun test execution.
42
+ Runtime PhaseStatus
43
+ }
44
+
45
+ // PackageResult describes one package-test result.
46
+ type PackageResult struct {
47
+ // PackagePath is the package under test.
48
+ PackagePath string
49
+ // TestPackagePath is the package variant that contains test functions.
50
+ TestPackagePath string
51
+ // TestImports are direct imports from selected test variants.
52
+ TestImports []string
53
+ // Tests are the selected tests for this package.
54
+ Tests []Test
55
+ // Action is the package result.
56
+ Action Action
57
+ // Phases records structured status for each runner phase.
58
+ Phases PackagePhases
59
+ // Owner is the primary owner classification for failures.
60
+ Owner Owner
61
+ // Error is the concise package failure message.
62
+ Error string
63
+ // Output is raw process output for the package.
64
+ Output string
65
+ // Elapsed is the package runtime.
66
+ Elapsed time.Duration
67
+ }
@@ -0,0 +1,145 @@
1
+ package gotest
2
+
3
+ import (
4
+ "path/filepath"
5
+ "slices"
6
+ "strings"
7
+ "time"
8
+
9
+ "github.com/pkg/errors"
10
+ )
11
+
12
+ // Request describes one GoScript package-test run.
13
+ type Request struct {
14
+ // Dir is the working directory for package loading.
15
+ Dir string
16
+ // Patterns are Go package patterns to test.
17
+ Patterns []string
18
+ // BuildTags are normalized into a Go -tags build flag.
19
+ BuildTags []string
20
+ // Run is the optional Go test name regexp.
21
+ Run string
22
+ // Count is the number of times to run matched tests.
23
+ Count int
24
+ // Short reports true from testing.Short in generated tests.
25
+ Short bool
26
+ // Timeout bounds compile, typecheck, and execution.
27
+ Timeout time.Duration
28
+ // Verbose emits test-level output.
29
+ Verbose bool
30
+ // WorkDir stores generated runner files and logs.
31
+ WorkDir string
32
+ // OutputRoot stores generated TypeScript packages.
33
+ OutputRoot string
34
+ }
35
+
36
+ type normalizedRequest struct {
37
+ Dir string
38
+ Patterns []string
39
+ BuildFlags []string
40
+ Run string
41
+ Count int
42
+ Short bool
43
+ Timeout time.Duration
44
+ Verbose bool
45
+ WorkDir string
46
+ OutputRoot string
47
+ }
48
+
49
+ func (r *Request) normalize() (*normalizedRequest, error) {
50
+ if r == nil {
51
+ return nil, errors.New("goscript test request cannot be nil")
52
+ }
53
+
54
+ dir := strings.TrimSpace(r.Dir)
55
+ if dir == "" {
56
+ dir = "."
57
+ }
58
+ absDir, err := filepath.Abs(dir)
59
+ if err != nil {
60
+ return nil, errors.Wrap(err, "resolve test working directory")
61
+ }
62
+
63
+ patterns := normalizePatterns(r.Patterns)
64
+ if len(patterns) == 0 {
65
+ return nil, errors.New("at least one Go package pattern is required")
66
+ }
67
+
68
+ count := r.Count
69
+ if count == 0 {
70
+ count = 1
71
+ }
72
+ if count < 0 {
73
+ return nil, errors.New("test count must be positive")
74
+ }
75
+
76
+ buildTags := normalizeBuildTags(r.BuildTags)
77
+ var buildFlags []string
78
+ if len(buildTags) != 0 {
79
+ buildFlags = append(buildFlags, "-tags="+strings.Join(buildTags, ","))
80
+ }
81
+
82
+ workDir := strings.TrimSpace(r.WorkDir)
83
+ if workDir != "" {
84
+ var err error
85
+ workDir, err = filepath.Abs(workDir)
86
+ if err != nil {
87
+ return nil, errors.Wrap(err, "resolve test work directory")
88
+ }
89
+ }
90
+
91
+ outputRoot := strings.TrimSpace(r.OutputRoot)
92
+ if outputRoot != "" {
93
+ var err error
94
+ outputRoot, err = filepath.Abs(outputRoot)
95
+ if err != nil {
96
+ return nil, errors.Wrap(err, "resolve test output root")
97
+ }
98
+ }
99
+
100
+ return &normalizedRequest{
101
+ Dir: absDir,
102
+ Patterns: patterns,
103
+ BuildFlags: buildFlags,
104
+ Run: strings.TrimSpace(r.Run),
105
+ Count: count,
106
+ Short: r.Short,
107
+ Timeout: r.Timeout,
108
+ Verbose: r.Verbose,
109
+ WorkDir: workDir,
110
+ OutputRoot: outputRoot,
111
+ }, nil
112
+ }
113
+
114
+ func normalizePatterns(patterns []string) []string {
115
+ if len(patterns) == 0 {
116
+ return nil
117
+ }
118
+ normalized := make([]string, 0, len(patterns))
119
+ for _, pattern := range patterns {
120
+ pattern = strings.TrimSpace(pattern)
121
+ if pattern != "" {
122
+ normalized = append(normalized, pattern)
123
+ }
124
+ }
125
+ return normalized
126
+ }
127
+
128
+ func normalizeBuildTags(tags []string) []string {
129
+ seen := make(map[string]bool)
130
+ var normalized []string
131
+ for _, value := range tags {
132
+ for _, tag := range strings.FieldsFunc(value, func(r rune) bool {
133
+ return r == ',' || r == ' ' || r == '\t' || r == '\n'
134
+ }) {
135
+ tag = strings.TrimSpace(tag)
136
+ if tag == "" || seen[tag] {
137
+ continue
138
+ }
139
+ seen[tag] = true
140
+ normalized = append(normalized, tag)
141
+ }
142
+ }
143
+ slices.Sort(normalized)
144
+ return normalized
145
+ }
@@ -0,0 +1,28 @@
1
+ package gotest
2
+
3
+ import "github.com/aperturerobotics/goscript/compiler"
4
+
5
+ // Result describes one GoScript package-test run.
6
+ type Result struct {
7
+ // WorkDir is the generated test workspace.
8
+ WorkDir string
9
+ // OutputRoot is the generated TypeScript package root.
10
+ OutputRoot string
11
+ // Packages are deterministic package-level test results.
12
+ Packages []PackageResult
13
+ // Diagnostics are compiler diagnostics surfaced during the run.
14
+ Diagnostics []compiler.Diagnostic
15
+ }
16
+
17
+ // Passed returns true when every package result passed or had no tests.
18
+ func (r *Result) Passed() bool {
19
+ if r == nil {
20
+ return false
21
+ }
22
+ for _, pkg := range r.Packages {
23
+ if pkg.Action == ActionFail {
24
+ return false
25
+ }
26
+ }
27
+ return true
28
+ }