v0.5.0 089fa12

sources_test.go RawHistoryFolder

1package scanner
2
3import (
4	"crypto/sha256"
5	"fmt"
6	"os"
7	"path/filepath"
8	"regexp"
9	"strings"
10	"testing"
11)
12
13func TestProtocolSourceChecksums(t *testing.T) {
14	root := filepath.Join("..", "..", "protocol")
15	content, err := os.ReadFile(filepath.Join(root, "SOURCE.md"))
16	if err != nil {
17		t.Fatal(err)
18	}
19	coreChecksum := regexp.MustCompile("(?m)^SHA-256: `([a-f0-9]{64})`\\.").FindSubmatch(content)
20	if coreChecksum == nil {
21		t.Fatal("core protocol source checksum is missing")
22	}
23	// Extension tables record upstream path, vendored path and SHA-256.
24	rows := regexp.MustCompile("(?m)^\\| `[^`]+` \\| `([^`]+)` \\| `([a-f0-9]{64})` \\|$").FindAllSubmatch(content, -1)
25	if len(rows) == 0 {
26		t.Fatal("no protocol source checksums found")
27	}
28	rows = append(rows, [][]byte{nil, []byte("wayland.xml"), coreChecksum[1]})
29	recorded := make(map[string]bool)
30	for _, row := range rows {
31		path, want := string(row[1]), string(row[2])
32		if !filepath.IsLocal(path) {
33			t.Fatalf("source path must be repository-relative: %q", path)
34		}
35		if recorded[path] {
36			t.Fatalf("duplicate source record: %s", path)
37		}
38		recorded[path] = true
39		t.Run(path, func(t *testing.T) {
40			data, err := os.ReadFile(filepath.Join(root, path))
41			if err != nil {
42				t.Fatal(err)
43			}
44			if got := fmt.Sprintf("%x", sha256.Sum256(data)); got != want {
45				t.Fatalf("SHA-256 %s, recorded %s", got, want)
46			}
47			if !strings.Contains(string(data), "<copyright>") {
48				t.Fatal("vendored XML is missing upstream copyright/license")
49			}
50		})
51	}
52	err = filepath.WalkDir(root, func(path string, entry os.DirEntry, err error) error {
53		if err != nil {
54			return err
55		}
56		if entry.IsDir() || filepath.Ext(path) != ".xml" {
57			return nil
58		}
59		rel, err := filepath.Rel(root, path)
60		if err != nil {
61			return err
62		}
63		if !recorded[filepath.ToSlash(rel)] {
64			t.Errorf("%s has no source/checksum record", rel)
65		}
66		return nil
67	})
68	if err != nil {
69		t.Fatal(err)
70	}
71}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 8

↑↓ moveenter openesc close