-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for LSIF Typed Running `src lsif upload` now converts LSIF Typed into LSIF Graph in the following scenarios: - When the provided `-file` flag matches the file extension ".lsif-typed" - When the provided `-file` flag points to a non-existent file, while the sibling `*.lsif-typed` file exists. Fixes https://github.com/sourcegraph/sourcegraph/issues/27405 * Fix ordering of how we initialize `*output.Output` * Add test cases for `handleLSIFTyped` function. * Remove redundant blank line * Use `t.TempDir()` to create temporary directory
- Loading branch information
Showing
5 changed files
with
172 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/sourcegraph/sourcegraph/lib/codeintel/lsiftyped" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
var exampleLsifTypedIndex = lsiftyped.Index{ | ||
Metadata: &lsiftyped.Metadata{ | ||
TextDocumentEncoding: lsiftyped.TextEncoding_UTF8, | ||
ToolInfo: &lsiftyped.ToolInfo{ | ||
Name: "hello", | ||
Version: "1.0.0", | ||
}, | ||
}, | ||
} | ||
|
||
var exampleLsifGraphString = `{"id":1,"version":"0.4.3","positionEncoding":"utf-8","toolInfo":{"name":"hello","version":"1.0.0"},"type":"vertex","label":"metaData"} | ||
` | ||
|
||
func exampleLsifTypedBytes(t *testing.T) []byte { | ||
bytes, err := proto.Marshal(&exampleLsifTypedIndex) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return bytes | ||
} | ||
|
||
func createTempLsifTypedFile(t *testing.T) (typedFile, graphFile string) { | ||
dir := t.TempDir() | ||
typedFile = filepath.Join(dir, "dump.lsif-typed") | ||
graphFile = filepath.Join(dir, "dump.lsif") | ||
err := os.WriteFile(typedFile, exampleLsifTypedBytes(t), 0755) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return typedFile, graphFile | ||
} | ||
|
||
func assertLsifGraphOutput(t *testing.T, lsifGraphFile, expectedGraphString string) { | ||
out := lsifUploadOutput() | ||
handleLSIFTyped(out) | ||
lsifGraph, err := os.ReadFile(lsifGraphFile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
obtained := string(lsifGraph) | ||
if obtained != expectedGraphString { | ||
t.Fatalf("unexpected LSIF output %s", obtained) | ||
} | ||
if lsifGraphFile != lsifUploadFlags.file { | ||
t.Fatalf("unexpected lsifUploadFlag.file value %s, expected %s", lsifUploadFlags.file, lsifGraphFile) | ||
} | ||
} | ||
|
||
func TestImplicitlyConvertLsifTypedIntoGraph(t *testing.T) { | ||
_, graphFile := createTempLsifTypedFile(t) | ||
lsifUploadFlags.file = graphFile | ||
assertLsifGraphOutput(t, graphFile, exampleLsifGraphString) | ||
} | ||
|
||
func TestImplicitlyIgnoreLsifTyped(t *testing.T) { | ||
_, graphFile := createTempLsifTypedFile(t) | ||
lsifUploadFlags.file = graphFile | ||
os.WriteFile(graphFile, []byte("hello world"), 0755) | ||
assertLsifGraphOutput(t, graphFile, "hello world") | ||
} | ||
|
||
func TestExplicitlyConvertLsifTypedIntoGraph(t *testing.T) { | ||
typedFile, graphFile := createTempLsifTypedFile(t) | ||
lsifUploadFlags.file = typedFile | ||
assertLsifGraphOutput(t, graphFile, exampleLsifGraphString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters