Skip to content

Commit 7eeefcf

Browse files
authored
Move reprolang to a top-level directory (#363)
Reprolang is a toy language that can be used to write very simple integration tests for scip. I find it to be very useful. I was surprised that it's stored in some deeply nested directory. Since the project is a language with its own indexer, I made it more isolated with its own go.mod. I've also migrated it to use tree-sitter/go-tree-sitter instead of no longer maintained smacker/go-tree-sitter.
1 parent 61f2dc7 commit 7eeefcf

File tree

78 files changed

+927
-671
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+927
-671
lines changed

bindings/go/scip/testutil/test_runner.go

Lines changed: 422 additions & 0 deletions
Large diffs are not rendered by default.

cmd/scip/test_test.go renamed to bindings/go/scip/testutil/test_runner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package testutil
22

33
import (
44
"testing"

checks.nix

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
pname = "scip-bindings-go";
2828
inherit version;
2929
src = ./.;
30-
vendorHash = "sha256-ywSR9yRysnm2E6kI8UJS6XcpuqKJF8wJpHcYS7TGmjI=";
30+
vendorHash = "sha256-JuGh7/CnpCWABK6WYE+Mo7P8X0glFrFa9ve9eO//1v8=";
3131
buildTags = [ "asserts" ];
3232
subPackages = [
3333
"bindings/go/scip"
@@ -56,19 +56,22 @@
5656

5757
reprolang =
5858
let
59-
reprolangVersion =
60-
(builtins.fromJSON (builtins.readFile ./cmd/scip/tests/reprolang/package.json)).version;
59+
reprolangVersion = (builtins.fromJSON (builtins.readFile ./reprolang/package.json)).version;
6160
in
62-
assert pkgs.lib.assertMsg (reprolangVersion == version)
63-
"Version mismatch in cmd/scip/tests/reprolang/package.json: expected ${version}, got ${reprolangVersion}";
61+
assert pkgs.lib.assertMsg (
62+
reprolangVersion == version
63+
) "Version mismatch in reprolang/package.json: expected ${version}, got ${reprolangVersion}";
6464
pkgs.buildGoModule {
6565
pname = "scip-reprolang";
6666
inherit version;
6767
src = ./.;
68-
vendorHash = "sha256-ywSR9yRysnm2E6kI8UJS6XcpuqKJF8wJpHcYS7TGmjI=";
68+
modRoot = "./reprolang";
69+
vendorHash = "sha256-H6RLXmQsufwKtI5BujsUEibVuCMpILqtX3W0Wg9m3T8=";
70+
proxyVendor = true;
71+
buildInputs = [ pkgs.tree-sitter ];
6972
subPackages = [
70-
"cmd/scip/tests/reprolang/src"
71-
"cmd/scip/tests/reprolang/bindings/go/repro"
73+
"grammar"
74+
"repro"
7275
];
7376
installPhase = "touch $out";
7477
};
@@ -83,11 +86,11 @@
8386
tree-sitter
8487
];
8588
buildPhase = ''
86-
cd cmd/scip/tests/reprolang
87-
cp -r src src-before
88-
tree-sitter generate --abi 14
89-
prettier --write 'src/grammar.json' 'src/node-types.json'
90-
diff -rq src-before src
89+
cd reprolang
90+
cp -r grammar grammar-before
91+
tree-sitter generate --abi 14 --output grammar
92+
prettier --write 'grammar/grammar.json' 'grammar/node-types.json'
93+
diff -rq grammar-before grammar
9194
'';
9295
installPhase = "touch $out";
9396
};

cmd/scip/main_test.go

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
package main
22

33
import (
4-
"bytes"
5-
"flag"
64
"fmt"
75
"os"
86
"path/filepath"
97
"strings"
108
"testing"
119

12-
"github.com/hexops/autogold/v2"
1310
"github.com/stretchr/testify/require"
14-
"golang.org/x/exp/slices"
15-
16-
"github.com/sourcegraph/scip/bindings/go/scip"
17-
"github.com/sourcegraph/scip/bindings/go/scip/testutil"
18-
"github.com/sourcegraph/scip/cmd/scip/tests/reprolang/bindings/go/repro"
1911
)
2012

2113
func TestMain(m *testing.M) {
@@ -55,164 +47,3 @@ func TestCLIReferenceInSync(t *testing.T) {
5547
check([]string{command.Name, "--help"}, fmt.Sprintf("subcommand %s", command.Name))
5648
}
5749
}
58-
59-
var debugSnapshotAbspaths = flag.Bool("debug-snapshot-abspaths", false, "use absolute paths in snapshot outputs, useful for making uploads to test code navigation")
60-
61-
// TestSCIPSnapshots runs all the snapshot tests.
62-
func TestSCIPSnapshots(t *testing.T) {
63-
cwd, err := os.Getwd()
64-
require.Nil(t, err)
65-
testDir := filepath.Join(cwd, "tests")
66-
testutil.SnapshotTest(t, testDir, func(inputDirectory, outputDirectory string, sources []*scip.SourceFile) []*scip.SourceFile {
67-
testName := filepath.Base(inputDirectory)
68-
var dependencies []*repro.Dependency
69-
rootDirectory := filepath.Dir(inputDirectory)
70-
dirs, err := os.ReadDir(rootDirectory)
71-
require.Nil(t, err)
72-
for _, dir := range dirs {
73-
if !dir.IsDir() {
74-
continue
75-
}
76-
if dir.Name() == testName {
77-
continue
78-
}
79-
dependencyRoot := filepath.Join(rootDirectory, dir.Name())
80-
dependencySources, err := scip.NewSourcesFromDirectory(dependencyRoot)
81-
require.Nil(t, err)
82-
dependencies = append(dependencies, &repro.Dependency{
83-
Package: &scip.Package{
84-
Manager: "repro_manager",
85-
Name: dir.Name(),
86-
Version: "1.0.0",
87-
},
88-
Sources: dependencySources,
89-
})
90-
}
91-
index, err := repro.Index("file:/"+inputDirectory, testName, sources, dependencies)
92-
require.Nil(t, err)
93-
symbolFormatter := scip.DescriptorOnlyFormatter
94-
symbolFormatter.IncludePackageName = func(name string) bool { return name != testName }
95-
snapshots, err := testutil.FormatSnapshots(index, "#", symbolFormatter, inputDirectory)
96-
require.Nil(t, err)
97-
if debugSnapshotAbspaths != nil && *debugSnapshotAbspaths {
98-
inputDirAbsPath, err := filepath.Abs(inputDirectory)
99-
require.Nil(t, err)
100-
index.Metadata.ProjectRoot = inputDirAbsPath
101-
} else {
102-
index.Metadata.ProjectRoot = "file:/root"
103-
}
104-
return snapshots
105-
})
106-
}
107-
108-
func unwrap[T any](v T, err error) func(*testing.T) T {
109-
return func(t *testing.T) T {
110-
require.NoError(t, err)
111-
return v
112-
}
113-
}
114-
115-
func TestSCIPTests(t *testing.T) {
116-
cwd := unwrap(os.Getwd())(t)
117-
testDir := filepath.Join(cwd, "tests", "test_cmd")
118-
testPaths := unwrap(os.ReadDir(testDir))(t)
119-
require.Truef(t, len(testPaths) >= 1, "Expected at least one test case in directory: %v", testDir)
120-
121-
os.Setenv("NO_COLOR", "1")
122-
t.Cleanup(func() {
123-
os.Unsetenv("NO_COLOR")
124-
})
125-
126-
type TestCase struct {
127-
dir string
128-
passOutput autogold.Value
129-
failOutput autogold.Value
130-
}
131-
132-
// To update the snapshot values, run 'go test ./cmd/scip -update'.
133-
testCases := []TestCase{
134-
{"roles",
135-
autogold.Expect("✓ passes.repro (3 assertions)\n"),
136-
autogold.Expect(`✗ fails-wrong-role.repro
137-
Failure [Ln: 1, Col: 13]
138-
Expected: 'reference reprolang repro_manager roles 1.0.0 fails-wrong-role.repro/hello().'
139-
Actual: 'definition reprolang repro_manager roles 1.0.0 fails-wrong-role.repro/hello().'
140-
✗ fails-wrong-symbol.repro
141-
Failure [Ln: 1, Col: 13]
142-
Expected: 'definition reprolang repro_manager roles 1.0.0 fails-wrong-role.repro/hello2().'
143-
Actual: 'definition reprolang repro_manager roles 1.0.0 fails-wrong-symbol.repro/hello().'
144-
`),
145-
},
146-
{"ranges",
147-
autogold.Expect("✓ passes.repro (3 assertions)\n"),
148-
autogold.Expect(`✗ fails.repro
149-
Failure [Ln: 1, Col: 10]
150-
Expected: 'definition passes.repro/hello().'
151-
Actual: <no attributes found>
152-
`),
153-
},
154-
{"diagnostics",
155-
autogold.Expect("✓ passes.repro (2 assertions)\n"),
156-
autogold.Expect(`✗ fails-incorrect-diagnostic.repro
157-
Failure [Ln: 1, Col: 11]
158-
Expected: 'diagnostic Warning:'
159-
'THIS IS NOT CORRECT'
160-
Actual: * 'definition reprolang repro_manager diagnostics 1.0.0 fails-incorrect-diagnostic.repro/deprecatedMethod.'
161-
* 'diagnostic Warning'
162-
'deprecated identifier'
163-
✗ fails-no-diagnostic.repro
164-
Failure [Ln: 1, Col: 11]
165-
Expected: 'diagnostic Warning:'
166-
'deprecated identifier'
167-
Actual: 'definition reprolang repro_manager diagnostics 1.0.0 fails-no-diagnostic.repro/hello().'
168-
`),
169-
},
170-
}
171-
172-
for _, testPath := range testPaths {
173-
require.Truef(t, slices.ContainsFunc(testCases, func(testCase TestCase) bool {
174-
return testCase.dir == testPath.Name()
175-
}), "Missing entry in testOutputs for %q", testPath.Name())
176-
}
177-
178-
for _, testCase := range testCases {
179-
var dirEntry os.DirEntry
180-
require.Truef(t, slices.ContainsFunc(testPaths, func(entry os.DirEntry) bool {
181-
if entry.Name() == testCase.dir {
182-
dirEntry = entry
183-
return true
184-
}
185-
return false
186-
}), "Stale entry in testOutputs for %q; did you rename or remove the directory", testCase.dir)
187-
188-
subtestDir := filepath.Join(testDir, dirEntry.Name())
189-
require.Truef(t, dirEntry.IsDir(), "not a directory: %q", subtestDir)
190-
191-
t.Run(testCase.dir, func(t *testing.T) {
192-
sources := unwrap(scip.NewSourcesFromDirectory(subtestDir))(t)
193-
index := unwrap(repro.Index("file:/"+subtestDir, dirEntry.Name(), sources, []*repro.Dependency{}))(t)
194-
195-
var passFiles, failFiles []string
196-
testFiles := unwrap(os.ReadDir(subtestDir))(t)
197-
for _, testFile := range testFiles {
198-
if strings.HasPrefix(testFile.Name(), "passes") {
199-
passFiles = append(passFiles, testFile.Name())
200-
} else if strings.HasPrefix(testFile.Name(), "fails") {
201-
failFiles = append(failFiles, testFile.Name())
202-
} else {
203-
t.Fatalf("Test files must start with 'passes' or 'fails'. Received %v", testFile.Name())
204-
}
205-
}
206-
207-
var passOutput bytes.Buffer
208-
err := testMain(subtestDir, passFiles, false, index, "#", &passOutput)
209-
require.NoError(t, err)
210-
testCase.passOutput.Equal(t, passOutput.String())
211-
212-
var failOutput bytes.Buffer
213-
err = testMain(subtestDir, failFiles, false, index, "#", &failOutput)
214-
require.Error(t, err)
215-
testCase.failOutput.Equal(t, failOutput.String())
216-
})
217-
}
218-
}

0 commit comments

Comments
 (0)