diff options
| -rw-r--r-- | executor/files.h | 1 | ||||
| -rw-r--r-- | executor/style_test.go | 2 | ||||
| -rw-r--r-- | executor/test.h | 90 | ||||
| -rw-r--r-- | pkg/runtest/executor_test.go | 3 |
4 files changed, 94 insertions, 2 deletions
diff --git a/executor/files.h b/executor/files.h index 23f06878e..7be826d0a 100644 --- a/executor/files.h +++ b/executor/files.h @@ -51,6 +51,7 @@ static std::vector<std::string> Glob(const std::string& pattern) files.push_back(file); } globfree(&buf); + debug("glob %s resolved to %zu files\n", pattern.c_str(), files.size()); return files; } diff --git a/executor/style_test.go b/executor/style_test.go index 7c32d4d10..ae3e9421b 100644 --- a/executor/style_test.go +++ b/executor/style_test.go @@ -54,7 +54,7 @@ if (foo) { }, { // These are also not properly stripped by pkg/csource. - pattern: `/\*[^{]`, + pattern: `/\*[^{/"]`, message: "Don't use /* */ block comments. Use // line comments instead", tests: []string{ `/* C++ comment */`, diff --git a/executor/test.h b/executor/test.h index 1ca3c6f26..e53f663b5 100644 --- a/executor/test.h +++ b/executor/test.h @@ -5,6 +5,11 @@ #include "test_linux.h" #endif +#include <algorithm> +#include <fcntl.h> +#include <sys/stat.h> +#include <unistd.h> + static int test_copyin() { static uint16 buf[3]; @@ -272,6 +277,90 @@ static int test_cover_filter() return ret; } +static bool test_one_glob(const char* pattern, std::vector<std::string> want) +{ + std::vector<std::string> got = Glob(pattern); + std::sort(want.begin(), want.end()); + std::sort(got.begin(), got.end()); + if (got == want) + return true; + printf("pattern '%s', want %zu files:\n", pattern, want.size()); + for (const auto& f : want) + printf("\t'%s'\n", f.c_str()); + printf("got %zu files:\n", got.size()); + for (const auto& f : got) + printf("\t'%s'\n", f.c_str()); + return false; +} + +static void must_mkdir(const char* dir) +{ + if (mkdir(dir, 0700)) + failmsg("mkdir failed", "dir=%s", dir); +} + +static void must_creat(const char* file) +{ + int fd = open(file, O_CREAT | O_EXCL, 0700); + if (fd == -1) + failmsg("open failed", "file=%s", file); + close(fd); +} + +static void must_link(const char* oldpath, const char* linkpath) +{ + if (link(oldpath, linkpath)) + failmsg("link failed", "oldpath=%s linkpath=%s", oldpath, linkpath); +} + +static void must_symlink(const char* oldpath, const char* linkpath) +{ + if (symlink(oldpath, linkpath)) + failmsg("symlink failed", "oldpath=%s linkpath=%s", oldpath, linkpath); +} + +static int test_glob() +{ + // Note: pkg/runtest.TestExecutor creates a temp dir for the test, + // so we create files in cwd and don't clean up. + if (!test_one_glob("glob/*", {})) + return 1; + must_mkdir("glob"); + if (!test_one_glob("glob/*", {})) + return 1; + must_mkdir("glob/dir1"); + must_creat("glob/file1"); + must_mkdir("glob/dir2"); + must_creat("glob/dir2/file21"); + must_mkdir("glob/dir3"); + must_creat("glob/dir3/file31"); + must_link("glob/dir3/file31", "glob/dir3/file32"); + must_symlink("file31", "glob/dir3/file33"); + must_symlink("deadlink", "glob/dir3/file34"); + must_symlink("../../glob", "glob/dir3/dir31"); + must_mkdir("glob/dir4"); + must_mkdir("glob/dir4/dir41"); + must_creat("glob/dir4/dir41/file411"); + must_symlink("dir4", "glob/dir5"); + must_mkdir("glob/dir6"); + must_mkdir("glob/dir6/dir61"); + must_creat("glob/dir6/dir61/file611"); + must_symlink("dir6/dir61", "glob/self"); + // Directories are not includes + not recursive (yet). + if (!test_one_glob("glob/*", { + "glob/file1", + })) + return 1; + if (!test_one_glob("glob/*/*", { + "glob/dir2/file21", + "glob/dir3/file31", + "glob/dir3/file32", // hard links are included + "glob/self/file611", // symlinks via name "self" are included + })) + return 1; + return 0; +} + static struct { const char* name; int (*f)(); @@ -283,6 +372,7 @@ static struct { {"test_kvm", test_kvm}, #endif {"test_cover_filter", test_cover_filter}, + {"test_glob", test_glob}, }; static int run_tests(const char* test) diff --git a/pkg/runtest/executor_test.go b/pkg/runtest/executor_test.go index db84da275..4d803283a 100644 --- a/pkg/runtest/executor_test.go +++ b/pkg/runtest/executor_test.go @@ -33,13 +33,14 @@ func TestExecutor(t *testing.T) { t.Skipf("skipping, broken cross-compiler: %v", sysTarget.BrokenCompiler) } t.Parallel() + dir := t.TempDir() target, err := prog.GetTarget(runtime.GOOS, sysTarget.Arch) if err != nil { t.Fatal(err) } bin := csource.BuildExecutor(t, target, "../..") // qemu-user may allow us to run some cross-arch binaries. - if _, err := osutil.RunCmd(time.Minute, "", bin, "test"); err != nil { + if _, err := osutil.RunCmd(time.Minute, dir, bin, "test"); err != nil { if sysTarget.Arch == runtime.GOARCH || sysTarget.VMArch == runtime.GOARCH { t.Fatal(err) } |
