From f12880688dad3dd9ac561927a765038d1c0990d4 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sat, 2 May 2026 02:08:25 +0900 Subject: [PATCH] internal/rosa/gnu: test skip helper The terribleness of GNU invites interesting helpers. Signed-off-by: Ophestra --- internal/rosa/gnu.go | 37 +++++++++++++++++++++++++++++++++++++ internal/rosa/gnu_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 internal/rosa/gnu_test.go diff --git a/internal/rosa/gnu.go b/internal/rosa/gnu.go index c568bbdc..0a944d6a 100644 --- a/internal/rosa/gnu.go +++ b/internal/rosa/gnu.go @@ -2,10 +2,47 @@ package rosa import ( "runtime" + "slices" + "strconv" + "strings" "hakurei.app/internal/pkg" ) +// skipGNUTests generates a string for skipping specific tests by number in a +// GNU test suite. This is nontrivial because the test suite does not support +// excluding tests in any way, so ranges for all but the skipped tests have to +// be specified instead. +// +// For example, to skip test 764, ranges around the skipped test must be +// specified: +// +// 1-763 765- +// +// Tests are numbered starting from 1. The resulting string is unquoted. +func skipGNUTests(tests ...int) string { + tests = slices.Clone(tests) + slices.Sort(tests) + + var buf strings.Builder + + if tests[0] != 1 { + buf.WriteString("1-") + } + + for i, n := range tests { + if n != 1 && (i == 0 || tests[i-1] != n-1) { + buf.WriteString(strconv.Itoa(n - 1)) + buf.WriteString(" ") + } + if i == len(tests)-1 || tests[i+1] != n+1 { + buf.WriteString(strconv.Itoa(n + 1)) + buf.WriteString("-") + } + } + return buf.String() +} + func (t Toolchain) newM4() (pkg.Artifact, string) { const ( version = "1.4.21" diff --git a/internal/rosa/gnu_test.go b/internal/rosa/gnu_test.go new file mode 100644 index 00000000..94d82618 --- /dev/null +++ b/internal/rosa/gnu_test.go @@ -0,0 +1,35 @@ +package rosa + +import ( + "slices" + "strconv" + "strings" + "testing" +) + +func TestSkipGNUTests(t *testing.T) { + t.Parallel() + + testCases := []struct { + tests []int + want string + }{ + {[]int{764}, "1-763 765-"}, + {[]int{764, 0xcafe, 37, 9}, "1-8 10-36 38-763 765-51965 51967-"}, + {[]int{1, 2, 0xbed}, "3-3052 3054-"}, + {[]int{3, 4}, "1-2 5-"}, + } + for _, tc := range testCases { + t.Run(strings.Join(slices.Collect(func(yield func(string) bool) { + for _, n := range tc.tests { + yield(strconv.Itoa(n)) + } + }), ","), func(t *testing.T) { + t.Parallel() + + if got := skipGNUTests(tc.tests...); got != tc.want { + t.Errorf("skipGNUTests: %q, want %q", got, tc.want) + } + }) + } +}