Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit d8d9b25

Browse files
author
Wojciech Jabłoński
committed
moved python script to go
Signed-off-by: Wojciech Jabłoński <[email protected]>
1 parent 5012732 commit d8d9b25

File tree

3 files changed

+66
-33
lines changed

3 files changed

+66
-33
lines changed

uast/diff/testdata/create_testdata.py

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"flag"
6+
"fmt"
7+
"os"
8+
"path/filepath"
9+
"strconv"
10+
)
11+
12+
// This is a script used to generate test data for the diff library. It uses pairs of files
13+
// to get diffed acquired from
14+
// https://github.com/vmarkovtsev/treediff/blob/49356e7f85c261ed88cf46326791765c58c22b5b/dataset/flask.tar.xz
15+
// It uses https://github.com/bblfsh/client-go#Installation to convert python sources into
16+
// uast yaml files.
17+
// This program outputs commands on the stdout - they are to be piped to sh/bash. It's a good
18+
// idea to inspect them before running by just reading the textual output of the program.
19+
// The program needs to be ran with proper commandline arguments. Example below. The cli arguments
20+
// are also documented if you run `./uast-diff-create-testdata --help`.
21+
// $ ./uast-diff-create-testdata -d ~/data/sourced/treediff/python-dataset -f smalltest.txt -o . | sh -
22+
23+
var datasetPath = flag.String("d", "./", "Path to the python-dataset (unpacked flask.tar.gz)")
24+
var testnamesPath = flag.String("f", "./smalltest.txt", "File with testnames")
25+
var outPath = flag.String("o", "./", "Output directory")
26+
27+
func firstFile(dirname string, fnamePattern string) string {
28+
fns, err := filepath.Glob(filepath.Join(dirname, fnamePattern))
29+
if err != nil {
30+
panic(err)
31+
}
32+
return fns[0]
33+
}
34+
35+
func main() {
36+
flag.Parse()
37+
_, err := os.Open(*datasetPath)
38+
if err != nil {
39+
panic(err)
40+
}
41+
42+
testnames, err := os.Open(*testnamesPath)
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
scanner := bufio.NewScanner(testnames)
48+
scanner.Split(bufio.ScanLines)
49+
50+
i := 0
51+
for scanner.Scan() {
52+
name := scanner.Text()
53+
if name == "" {
54+
continue
55+
}
56+
src := firstFile(*datasetPath, name+"_before*.src")
57+
dst := firstFile(*datasetPath, name+"_after*.src")
58+
iStr := strconv.Itoa(i)
59+
fmt.Println("bblfsh-cli -l python " + src + " -o yaml > " +
60+
filepath.Join(*outPath, iStr+"_src.uast"))
61+
fmt.Println("bblfsh-cli -l python " + dst + " -o yaml > " +
62+
filepath.Join(*outPath, iStr+"_dst.uast"))
63+
i = i + 1
64+
}
65+
66+
}
1.93 MB
Binary file not shown.

0 commit comments

Comments
 (0)