Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: batch of minor changes #183

Merged
merged 9 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ benchmarks/output
Makefile.main
.shared
.idea
.docsrv-resources
.docsrv-resources
build/
java/lib/
26 changes: 11 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ $(DOCS_PATH)/Makefile.inc:

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
RESOURCES_DIR=./.shared
LINUX_DIR=$(RESOURCES_DIR)/linux-x86-64
Expand All @@ -50,21 +44,21 @@ clean-shared:
clean: clean-linguist clean-shared

code-generate: $(LINGUIST_PATH)
mkdir -p data
mkdir -p data && \
go run internal/code-generator/main.go

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)
go test -run=NONE -bench=. -benchtime=5us && benchmarks/linguist-samples.rb

benchmarks-slow: $(LINGUST_PATH)
mkdir -p benchmarks/output && 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
go test -run=NONE -bench=. -benchtime=5us && \
benchmarks/linguist-samples.rb

build-cli:
go build -o enry -ldflags "$(LOCAL_LDFLAGS)" cmd/enry/main.go
benchmarks-slow: $(LINGUIST_PATH)
mkdir -p benchmarks/output && \
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

linux-shared: $(LINUX_SHARED_LIB)

Expand All @@ -79,3 +73,5 @@ $(LINUX_SHARED_LIB):
mkdir -p $(LINUX_DIR) && \
GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o $(LINUX_SHARED_LIB) $(NATIVE_LIB) && \
mv $(LINUX_DIR)/$(HEADER_FILE) $(RESOURCES_DIR)/$(HEADER_FILE)

.PHONY: benchmarks benchmarks-samples benchmarks-slow
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ go get gopkg.in/src-d/enry.v1/...

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`.

Expand Down Expand Up @@ -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
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
------------
Expand All @@ -203,7 +204,7 @@ Enry's language detection has been compared with Linguist's one. In order to do

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
detection was in the range of the time interval indicated in the x axis.
Expand Down
10 changes: 6 additions & 4 deletions benchmarks/parse.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

cd benchmarks/output && go run ../parser/main.go -outdir ../csv && \
cd ../csv && go run ../parser/main.go -distribution
#!/usr/bin/env bash
set -e

bzz marked this conversation as resolved.
Show resolved Hide resolved
cd benchmarks/output
go run ../parser/main.go -outdir ../csv
cd ../csv
go run ../parser/main.go -distribution
8 changes: 5 additions & 3 deletions benchmarks/run-benchmarks.sh
Original file line number Diff line number Diff line change
@@ -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 && \
benchmarks/linguist-total.rb 5 >benchmarks/output/linguist_total.bench
mkdir -p benchmarks/output
go test -run NONE -bench=. -benchtime=120s -timeout=100h > benchmarks/output/enry_total.bench
benchmarks/linguist-total.rb 5 > benchmarks/output/linguist_total.bench
9 changes: 6 additions & 3 deletions benchmarks/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/sh
#!/usr/bin/env bash
set -e

benchmarks/run-benchmarks.sh && make benchmarks-slow && \
benchmarks/parse.sh && benchmarks/plot-histogram.gp
benchmarks/run-benchmarks.sh
make benchmarks-slow
benchmarks/parse.sh
benchmarks/plot-histogram.gp
2 changes: 1 addition & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type EnryTestSuite struct {
cloned bool
}

func TestEnryTestSuite(t *testing.T) {
func Test_EnryTestSuite(t *testing.T) {
suite.Run(t, new(EnryTestSuite))
}

Expand Down
33 changes: 17 additions & 16 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
)

func (s *EnryTestSuite) TestIsAuxiliaryLanguage() {
func TestIsAuxiliaryLanguage(t *testing.T) {
type testType struct {
name string
lang string
Expand All @@ -30,11 +30,12 @@ func (s *EnryTestSuite) TestIsAuxiliaryLanguage() {

for _, test := range tests {
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 {
name string
path string
Expand All @@ -53,11 +54,11 @@ func (s *EnryTestSuite) TestIsVendor() {

for _, test := range tests {
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 {
name string
path string
Expand All @@ -69,11 +70,11 @@ func (s *EnryTestSuite) TestIsDocumentation() {

for _, test := range tests {
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 {
name string
path string
Expand All @@ -88,11 +89,11 @@ func (s *EnryTestSuite) TestIsImage() {

for _, test := range tests {
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 {
name string
path string
Expand All @@ -106,11 +107,11 @@ func (s *EnryTestSuite) TestGetMimeType() {

for _, test := range tests {
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 {
name string
path string
Expand All @@ -123,11 +124,11 @@ func (s *EnryTestSuite) TestIsConfiguration() {

for _, test := range tests {
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 {
name string
data []byte
Expand All @@ -140,11 +141,11 @@ func (s *EnryTestSuite) TestIsBinary() {

for _, test := range tests {
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 {
name string
path string
Expand All @@ -156,7 +157,7 @@ func (s *EnryTestSuite) TestIsDotFile() {

for _, test := range tests {
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))
}
}

Expand Down