From 411b67c10fcf757eca8e065f3e8f6f75b9762b9d Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Sat, 6 Jul 2024 08:25:12 -0700 Subject: [PATCH 1/2] test: correctly makes all example tests runnable Signed-off-by: Takeshi Yoneda --- Makefile | 2 +- experimental/close_example_test.go | 2 ++ experimental/sysfs/config_example_test.go | 6 ++++++ fsconfig_example_test.go | 2 ++ sys/stat_example_test.go | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d2f9a51cb4..0b1663f41d 100644 --- a/Makefile +++ b/Makefile @@ -187,7 +187,7 @@ golangci_lint_goarch ?= $(shell go env GOARCH) .PHONY: lint lint: $(golangci_lint_path) - @GOARCH=$(golangci_lint_goarch) CGO_ENABLED=0 $(golangci_lint_path) run --timeout 5m + @GOARCH=$(golangci_lint_goarch) CGO_ENABLED=0 $(golangci_lint_path) run --timeout 5m -E testableexamples .PHONY: format format: diff --git a/experimental/close_example_test.go b/experimental/close_example_test.go index 59eb08e89c..0c0a31794d 100644 --- a/experimental/close_example_test.go +++ b/experimental/close_example_test.go @@ -24,4 +24,6 @@ func Example_closeNotifier() { default: // do some more work with the module } + + // Output: } diff --git a/experimental/sysfs/config_example_test.go b/experimental/sysfs/config_example_test.go index 6c54a449fe..021a3c491d 100644 --- a/experimental/sysfs/config_example_test.go +++ b/experimental/sysfs/config_example_test.go @@ -20,6 +20,8 @@ func ExampleAdaptFS() { moduleConfig = wazero.NewModuleConfig(). WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/")) + + // Output: } // This example shows how to configure a sysfs.DirFS @@ -28,6 +30,8 @@ func ExampleDirFS() { moduleConfig = wazero.NewModuleConfig(). WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(root, "/")) + + // Output: } // This example shows how to configure a sysfs.ReadFS @@ -37,4 +41,6 @@ func ExampleReadFS() { moduleConfig = wazero.NewModuleConfig(). WithFSConfig(wazero.NewFSConfig().(sysfs.FSConfig).WithSysFSMount(readOnly, "/")) + + // Output: } diff --git a/fsconfig_example_test.go b/fsconfig_example_test.go index 882e152b49..0315c8c1b0 100644 --- a/fsconfig_example_test.go +++ b/fsconfig_example_test.go @@ -24,4 +24,6 @@ func Example_fsConfig() { moduleConfig = wazero.NewModuleConfig(). // Make "index.html" accessible to the guest as "/index.html". WithFSConfig(wazero.NewFSConfig().WithFSMount(rooted, "/")) + + // Output: } diff --git a/sys/stat_example_test.go b/sys/stat_example_test.go index 9b75eb58cf..416949274b 100644 --- a/sys/stat_example_test.go +++ b/sys/stat_example_test.go @@ -21,6 +21,8 @@ func Example_epochNanos() { // Generate a fake Atim using sys.Walltime passed to wazero.ModuleConfig. sec, nsec := walltime() st.Atim = sec*1e9 + int64(nsec) + + // Output: } type fileInfoWithSys struct { @@ -35,4 +37,6 @@ func Example_inode() { st := sys.NewStat_t(info) st.Ino = math.MaxUint64 // arbitrary non-zero value info = &fileInfoWithSys{info, st} + + // Output: } From a6f69d98cb9dd80592cd13dea668023297eb7821 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Sat, 6 Jul 2024 08:38:16 -0700 Subject: [PATCH 2/2] fix Signed-off-by: Takeshi Yoneda --- experimental/close_example_test.go | 2 +- sys/stat_example_test.go | 42 ------------------------------ 2 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 sys/stat_example_test.go diff --git a/experimental/close_example_test.go b/experimental/close_example_test.go index 0c0a31794d..ebb701c29c 100644 --- a/experimental/close_example_test.go +++ b/experimental/close_example_test.go @@ -12,7 +12,7 @@ var ctx context.Context func Example_closeNotifier() { closeCh := make(chan struct{}) ctx = experimental.WithCloseNotifier( - ctx, + context.Background(), experimental.CloseNotifyFunc(func(context.Context, uint32) { close(closeCh) }), ) diff --git a/sys/stat_example_test.go b/sys/stat_example_test.go deleted file mode 100644 index 416949274b..0000000000 --- a/sys/stat_example_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package sys_test - -import ( - "io/fs" - "math" - - "github.com/tetratelabs/wazero/sys" -) - -var ( - walltime sys.Walltime - info fs.FileInfo - st sys.Stat_t -) - -// This shows typical conversions to sys.EpochNanos type, for sys.Stat_t fields. -func Example_epochNanos() { - // Convert an adapted fs.File's fs.FileInfo to Mtim. - st.Mtim = info.ModTime().UnixNano() - - // Generate a fake Atim using sys.Walltime passed to wazero.ModuleConfig. - sec, nsec := walltime() - st.Atim = sec*1e9 + int64(nsec) - - // Output: -} - -type fileInfoWithSys struct { - fs.FileInfo - st sys.Stat_t -} - -func (f *fileInfoWithSys) Sys() any { return &f.st } - -// This shows how to return data not defined in fs.FileInfo, notably sys.Inode. -func Example_inode() { - st := sys.NewStat_t(info) - st.Ino = math.MaxUint64 // arbitrary non-zero value - info = &fileInfoWithSys{info, st} - - // Output: -}