Maintenance: batch of minor changes (#183)

* exclude build artifacts from git
* build: simplify building by using src-d/ci
* bench: simplify&fix shell runners
* build: simplify benchmarks* targets
* test: remove dependency on single test suite
* doc: rel image link + linguist cli difference highlight
* suggestions from code review
* bench: add fail fast to all shell runners

Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
Alexander
2018-12-27 11:55:34 +01:00
committed by GitHub
parent 84b9e638a4
commit ef50154395
8 changed files with 52 additions and 45 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ Makefile.main
.shared .shared
.idea .idea
.docsrv-resources .docsrv-resources
build/
java/lib/

View File

@ -23,12 +23,6 @@ $(DOCS_PATH)/Makefile.inc:
LINGUIST_PATH = .linguist LINGUIST_PATH = .linguist
# build CLI
LOCAL_TAG := $(shell git describe --tags --abbrev=0)
LOCAL_COMMIT := $(shell git rev-parse --short HEAD)
LOCAL_BUILD := $(shell date +"%m-%d-%Y_%H_%M_%S")
LOCAL_LDFLAGS = -s -X main.version=$(LOCAL_TAG) -X main.build=$(LOCAL_BUILD) -X main.commit=$(LOCAL_COMMIT)
# shared objects # shared objects
RESOURCES_DIR=./.shared RESOURCES_DIR=./.shared
LINUX_DIR=$(RESOURCES_DIR)/linux-x86-64 LINUX_DIR=$(RESOURCES_DIR)/linux-x86-64
@ -50,21 +44,21 @@ clean-shared:
clean: clean-linguist clean-shared clean: clean-linguist clean-shared
code-generate: $(LINGUIST_PATH) code-generate: $(LINGUIST_PATH)
mkdir -p data mkdir -p data && \
go run internal/code-generator/main.go go run internal/code-generator/main.go
benchmarks: $(LINGUIST_PATH) benchmarks: $(LINGUIST_PATH)
go test -run=NONE -bench=. && benchmarks/linguist-total.sh go test -run=NONE -bench=. && \
benchmarks/linguist-total.rb
benchmarks-samples: $(LINGUIST_PATH) benchmarks-samples: $(LINGUIST_PATH)
go test -run=NONE -bench=. -benchtime=5us && benchmarks/linguist-samples.rb go test -run=NONE -bench=. -benchtime=5us && \
benchmarks/linguist-samples.rb
benchmarks-slow: $(LINGUST_PATH) benchmarks-slow: $(LINGUIST_PATH)
mkdir -p benchmarks/output && go test -run=NONE -bench=. -slow -benchtime=100ms -timeout=100h >benchmarks/output/enry_samples.bench && \ mkdir -p benchmarks/output && \
benchmarks/linguist-samples.rb 5 >benchmarks/output/linguist_samples.bench go test -run=NONE -bench=. -slow -benchtime=100ms -timeout=100h > benchmarks/output/enry_samples.bench && \
benchmarks/linguist-samples.rb 5 > benchmarks/output/linguist_samples.bench
build-cli:
go build -o enry -ldflags "$(LOCAL_LDFLAGS)" cmd/enry/main.go
linux-shared: $(LINUX_SHARED_LIB) linux-shared: $(LINUX_SHARED_LIB)
@ -79,3 +73,5 @@ $(LINUX_SHARED_LIB):
mkdir -p $(LINUX_DIR) && \ mkdir -p $(LINUX_DIR) && \
GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o $(LINUX_SHARED_LIB) $(NATIVE_LIB) && \ GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o $(LINUX_SHARED_LIB) $(NATIVE_LIB) && \
mv $(LINUX_DIR)/$(HEADER_FILE) $(RESOURCES_DIR)/$(HEADER_FILE) mv $(LINUX_DIR)/$(HEADER_FILE) $(RESOURCES_DIR)/$(HEADER_FILE)
.PHONY: benchmarks benchmarks-samples benchmarks-slow

View File

@ -14,7 +14,7 @@ go get gopkg.in/src-d/enry.v1/...
To build enry's CLI you must run To build enry's CLI you must run
make build-cli make build
this will generate a binary in the project's root directory called `enry`. You can then move this binary to anywhere in your `PATH`. this will generate a binary in the project's root directory called `enry`. You can then move this binary to anywhere in your `PATH`.
@ -195,6 +195,7 @@ expression](https://github.com/github/linguist/blob/master/lib/linguist/heuristi
for `*.sql` files right. This expression doesn't comply with the pattern for the for `*.sql` files right. This expression doesn't comply with the pattern for the
rest in [heuristics.rb](https://github.com/github/linguist/blob/master/lib/linguist/heuristics.rb). rest in [heuristics.rb](https://github.com/github/linguist/blob/master/lib/linguist/heuristics.rb).
`enry` [CLI tool](#cli) does not require a full Git repository to be present in filesystem in order to report languages.
Benchmarks Benchmarks
------------ ------------
@ -203,7 +204,7 @@ Enry's language detection has been compared with Linguist's one. In order to do
We got these results: We got these results:
![histogram](https://raw.githubusercontent.com/src-d/enry/master/benchmarks/histogram/distribution.png) ![histogram](benchmarks/histogram/distribution.png)
The histogram represents the number of files for which spent time in language The histogram represents the number of files for which spent time in language
detection was in the range of the time interval indicated in the x axis. detection was in the range of the time interval indicated in the x axis.

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/usr/bin/env bash
set -e
cd benchmarks/output && go run ../parser/main.go -outdir ../csv && \
cd ../csv && go run ../parser/main.go -distribution
cd benchmarks/output
go run ../parser/main.go -outdir ../csv
cd ../csv
go run ../parser/main.go -distribution

View File

@ -1,4 +1,6 @@
#!/bin/sh #!/usr/bin/env bash
set -e
mkdir -p benchmarks/output && go test -run NONE -bench=. -benchtime=120s -timeout=100h >benchmarks/output/enry_total.bench && \ mkdir -p benchmarks/output
benchmarks/linguist-total.rb 5 >benchmarks/output/linguist_total.bench go test -run NONE -bench=. -benchtime=120s -timeout=100h > benchmarks/output/enry_total.bench
benchmarks/linguist-total.rb 5 > benchmarks/output/linguist_total.bench

View File

@ -1,4 +1,7 @@
#!/bin/sh #!/usr/bin/env bash
set -e
benchmarks/run-benchmarks.sh && make benchmarks-slow && \ benchmarks/run-benchmarks.sh
benchmarks/parse.sh && benchmarks/plot-histogram.gp make benchmarks-slow
benchmarks/parse.sh
benchmarks/plot-histogram.gp

View File

@ -24,7 +24,7 @@ type EnryTestSuite struct {
cloned bool cloned bool
} }
func TestEnryTestSuite(t *testing.T) { func Test_EnryTestSuite(t *testing.T) {
suite.Run(t, new(EnryTestSuite)) suite.Run(t, new(EnryTestSuite))
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func (s *EnryTestSuite) TestIsAuxiliaryLanguage() { func TestIsAuxiliaryLanguage(t *testing.T) {
type testType struct { type testType struct {
name string name string
lang string lang string
@ -30,11 +30,12 @@ func (s *EnryTestSuite) TestIsAuxiliaryLanguage() {
for _, test := range tests { for _, test := range tests {
is := IsAuxiliaryLanguage(test.lang) is := IsAuxiliaryLanguage(test.lang)
assert.Equal(s.T(), is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) assert.Equal(t, is, test.expected,
fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
} }
} }
func (s *EnryTestSuite) TestIsVendor() { func TestIsVendor(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
path string path string
@ -53,11 +54,11 @@ func (s *EnryTestSuite) TestIsVendor() {
for _, test := range tests { for _, test := range tests {
is := IsVendor(test.path) is := IsVendor(test.path)
assert.Equal(s.T(), is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
} }
} }
func (s *EnryTestSuite) TestIsDocumentation() { func TestIsDocumentation(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
path string path string
@ -69,11 +70,11 @@ func (s *EnryTestSuite) TestIsDocumentation() {
for _, test := range tests { for _, test := range tests {
is := IsDocumentation(test.path) is := IsDocumentation(test.path)
assert.Equal(s.T(), is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
} }
} }
func (s *EnryTestSuite) TestIsImage() { func TestIsImage(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
path string path string
@ -88,11 +89,11 @@ func (s *EnryTestSuite) TestIsImage() {
for _, test := range tests { for _, test := range tests {
is := IsImage(test.path) is := IsImage(test.path)
assert.Equal(s.T(), is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
} }
} }
func (s *EnryTestSuite) TestGetMimeType() { func TestGetMimeType(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
path string path string
@ -106,11 +107,11 @@ func (s *EnryTestSuite) TestGetMimeType() {
for _, test := range tests { for _, test := range tests {
is := GetMimeType(test.path, test.lang) is := GetMimeType(test.path, test.lang)
assert.Equal(s.T(), is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
} }
} }
func (s *EnryTestSuite) TestIsConfiguration() { func TestIsConfiguration(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
path string path string
@ -123,11 +124,11 @@ func (s *EnryTestSuite) TestIsConfiguration() {
for _, test := range tests { for _, test := range tests {
is := IsConfiguration(test.path) is := IsConfiguration(test.path)
assert.Equal(s.T(), is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
} }
} }
func (s *EnryTestSuite) TestIsBinary() { func TestIsBinary(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
data []byte data []byte
@ -140,11 +141,11 @@ func (s *EnryTestSuite) TestIsBinary() {
for _, test := range tests { for _, test := range tests {
is := IsBinary(test.data) is := IsBinary(test.data)
assert.Equal(s.T(), is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
} }
} }
func (s *EnryTestSuite) TestIsDotFile() { func TestIsDotFile(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
path string path string
@ -156,7 +157,7 @@ func (s *EnryTestSuite) TestIsDotFile() {
for _, test := range tests { for _, test := range tests {
is := IsDotFile(test.path) is := IsDotFile(test.path)
assert.Equal(s.T(), test.expected, is, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected)) assert.Equal(t, test.expected, is, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
} }
} }