You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 851e90b
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/development.md
+14-8Lines changed: 14 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,8 @@ lib/foojay.lua the Foojay request, and fixes to what it answers
18
18
lib/github_mirror.lua the mirror of the downloads from GitHub
19
19
lib/installed_version.lua matching against installed names
20
20
lib/loongnix.lua the Loongnix archive
21
-
tests/*_test.lua offline hook tests
21
+
tests/*_test.lua offline hook tests, run by vfox plugin test
22
+
tests/post_install_layouts.lua the macOS layouts PostInstall handles, with its real shell script
22
23
tests/fixtures/loongnix/ a saved copy of the Loongnix archive listing
23
24
tests/e2e/ container tests, see e2e.md
24
25
Injection.lua type hints for what vfox injects, never loaded
@@ -69,21 +70,26 @@ SDKMAN spells some things differently (`jbr`, `21.0.12.fx-zulu`, `21.0.12-fx+1.1
69
70
70
71
## Tests
71
72
72
-
The hook tests run offline under `gopher-lua`, the Lua interpreter vfox embeds. Every `tests/*_test.lua`is a test, and a new one needs no entry anywhere:
73
+
The hook tests run offline under `vfox plugin test`, which vfox 1.0.13 and later has. It finds every `tests/**/*_test.lua`and runs each file in a VM of its own, so a new test file needs no entry anywhere:
73
74
74
75
```bash
75
-
printf'%s\0' tests/*_test.lua | xargs -0 -n1 -t go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1
76
+
vfox plugin test.
77
+
vfox plugin test. --file tests/pre_use_test.lua
76
78
```
77
79
78
-
One file alone:
80
+
Run it from the repository root. The Test Plugin workflow installs the release pinned in `.github/workflows/test.yml`, and the dev container carries the same one.
81
+
82
+
A test file calls `test.load()` from `vfox.test` once, and calls the real hooks through what it returns, as in `plugin:PreInstall({ version = "21-tem" })`. `test.load` takes the platform (`os`, `arch`), the environment variables (`env`) and a function that answers every HTTP request (`http`). The modules in `lib` can be required after it, and `RUNTIME.osType` and `RUNTIME.archType` can be changed to try another platform. See vfox's [Test and debug a plugin](https://vfox.dev/plugins/create/testing.html). The context and the result of a hook go through the decoding vfox does, so a hook that returns a bare string where vfox wants a table fails the test, and a string the result lacks comes back as `""`, not `nil`.
83
+
84
+
The VM disables `os.execute` and `io.popen`, so `tests/pre_install_test.lua` answers the `ldd --version` that decides between glibc and musl itself. It keeps Foojay's answers in a table at the top, keyed by `<distribution> [<version>]`, with `windows` or `macos` in front for those systems, and its `http` function sends them as JSON. Add the answer a new case needs there, and note the day you observed it.
85
+
86
+
`tests/post_install_layouts.lua` is the one test that is not a `*_test.lua`: it runs the shell script of `PostInstall` on directories it makes, which the VM does not allow. It runs under `gopher-lua`, the Lua interpreter vfox embeds:
79
87
80
88
```bash
81
-
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/pre_use_test.lua
89
+
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/post_install_layouts.lua
82
90
```
83
91
84
-
Run them from the repository root. `glua` runs the one script it is given and passes the rest to it as `arg`, so `glua tests/*_test.lua` would run the first file and pass. `xargs -n1` starts one `glua` per file, because the files replace globals (`os.getenv`, `package.preload`) that the next one must not see, and it runs the rest after a failure. Every test file loads `tests/support.lua`, which stubs `vfox.strings`, and `tests/pre_install_test.lua` and `tests/loongnix_test.lua` stub `http` and `json` themselves. `tests/pre_install_test.lua` keeps Foojay's answers in a table at the top, keyed by `<distribution> [<version>]`, with `windows` or `macos` in front for those systems. Add the answer a new case needs there, and note the day you observed it. Lint, license headers and the container tests are in [e2e.md](e2e.md#local-checks).
85
-
86
-
vfox 1.0.13 and later also has `vfox plugin test`, which finds `tests/**/*_test.lua` by itself and runs each file with fresh globals. It fails all of these files: it requires a call to `test.load()` from `vfox.test`, which none of them makes, and its test VM disables `os.execute` and `io.popen` by default, which `tests/post_install_test.lua` (the shell script of `PostInstall`) and `tests/pre_install_test.lua` (`ldd --version` in `lib/foojay.lua`) run. So the tests run under `glua`.
92
+
Lint, license headers and the container tests are in [e2e.md](e2e.md#local-checks).
87
93
88
94
To call a single hook against the real Foojay, vfox 1.0.13 and later has `vfox plugin run`. It does not register the plugin, and `--os` and `--arch` answer for another platform:
0 commit comments