Skip to content

Commit

Permalink
Updated dependencies, cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Xie committed Sep 5, 2018
1 parent ae3ccc4 commit 55a0b32
Show file tree
Hide file tree
Showing 43 changed files with 1,384 additions and 597 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 67 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,49 @@ COVER_OUT = coverage.out

## ------ Commands (targets) -----
## Prevent targeting filenames...
.PHONY: default run build install get update review review-race review-bench \
check fmt test test-v test-race bench
.PHONY: default init run build install get update fix review review-race \
review-bench check fmt test test-v test-race bench

## Default target when no arguments are given to make (build and run program).
default: build run

## Initializes a Go module in the current directory.
init:
@printf "Initializing Go module:\n"
@go mod init

## Builds and runs the program (package must be main).
run:
@if [ -f ".env.sh" ]; then \
printf 'Exporting environment variables by sourcing ".env.sh"... '; \
. .env.sh; \
echo "done."; \
printf "done.\n"; \
fi
@if [ -f "$(PKG_NAME)" ]; then \
echo 'Running "$(PKG_NAME)"...'; \
printf 'Running "$(PKG_NAME)"...\n'; \
./$(PKG_NAME); \
else echo '[ERROR] Could not find program "$(PKG_NAME)".'; \
else printf '[ERROR] Could not find program "$(PKG_NAME)".\n'; \
fi

## Builds the program specified by the main package.
build:
@printf "Building... "
@GOBUILD_OUT="$$(go build 2>&1)"; \
if [ -n "$$GOBUILD_OUT" ]; then \
echo "\n[ERROR] Failed to build program:"; \
echo $$GOBUILD_OUT; \
else echo "done."; \
printf "\n[ERROR] Failed to build program:\n"; \
printf "$$GOBUILD_OUT\n"; \
exit 1; \
else printf "done.\n"; \
fi

install:
@printf 'Installing with "go install"... '
@GOINSTALL_OUT="$$(go install 2>&1)"; \
if [ -n "$$GOBUILD_OUT" ]; then \
echo "\n[ERROR] failed to install:"; \
echo "$$GOINSTALL_OUT"; \
else echo "done."; \
printf "\n[ERROR] failed to install:\n"; \
printf "$$GOINSTALL_OUT\n"; \
exit 1; \
else printf "done.\n"; \
fi


Expand All @@ -56,28 +63,38 @@ get:
@printf 'Installing package dependencies with "go get"... '
@GOGET_OUT="$$(go get ./... 2>&1)"; \
if [ -n "$$GOGET_OUT" ]; then \
echo "\n[ERROR] Failed to install package dependencies:"; \
echo "$$GOGET_OUT"; \
else echo "done."; \
printf "\n[ERROR] Failed to install package dependencies:\n"; \
printf "$$GOGET_OUT\n"; \
exit 1; \
else printf "done.\n"; \
fi

## Installs and updates package dependencies.
update:
@printf 'Installing and updating package dependencies with "go get"... '
@GOGET_OUT="$$(go get -u 2>&1)"; \
if [ -n "$$GOGET_OUT" ]; then \
echo "\n[ERROR] Failed to install package dependencies:"; \
echo "$$GOGET_OUT"; \
else echo "done."; \
printf "\n[ERROR] Failed to install package dependencies:\n"; \
printf "$$GOGET_OUT\n"; \
exit 1; \
else printf "done.\n"; \
fi

## Fixes Go code using "go fix"
fix:
@printf 'Fixing Go code with "go fix":\n'
@go fix


## Formats, checks, and tests the code.
review: fmt check test
review-v: fmt check test-v
## Like "review", but tests for race conditions.
review-race: fmt check test-race
review-race-v: fmt check test-race-v
## Like "review-race", but includes benchmarks.
review-bench: fmt check test-race bench
review-bench: review-race bench
review-bench-v: review-race bench-v


## Checks for formatting, linting, and suspicious code.
Expand All @@ -86,53 +103,67 @@ check:
@printf "Check fmt... "
@GOFMT_OUT="$$(gofmt -l $(SRC_FILES) 2>&1)"; \
if [ -n "$$GOFMT_OUT" ]; then \
echo '\n[WARN] Fix formatting issues in the following files with \
"make fmt":'; \
echo "$$GOFMT_OUT\n"; \
else echo "ok"; \
printf '\n[WARN] Fix formatting issues in the following files with \
"make fmt":\n'; \
printf "$$GOFMT_OUT\n"; \
exit 1; \
else printf "ok\n"; \
fi
## Lint files...
@printf "Check lint... "
@GOLINT_OUT="$(for PKG in "$(SRC_PKGS)"; do golint $$PKG 2>&1; done)"; \
if [ -n "$$GOLINT_OUT" ]; then \
printf "\n"; \
for PKG in "$$GOLINT_OUT"; do \
echo "$$PKG"; \
printf "$$PKG\n"; \
done; \
printf "\n"; \
else echo "ok"; \
exit 1; \
else printf "ok\n"; \
fi
## Check suspicious code...
@printf "Check vet... "
@GOVET_OUT="$$(go vet 2>&1)"; \
if [ -n "$$GOVET_OUT" ]; then \
echo '\n[WARN] Fix suspicious code from "go vet":'; \
echo "$$GOVET_OUT\n"; \
else echo "ok"; \
printf '\n[WARN] Fix suspicious code from "go vet":\n'; \
printf "$$GOVET_OUT\n"; \
exit 1; \
else printf "ok\n"; \
fi

## Reformats code according to "gofmt".
fmt:
@printf "Formatting source files... "
@GOFMT_OUT="$$(gofmt -l -s -w $(SRC_FILES) 2>&1)"; \
if [ -n "$$GOFMT_OUT" ]; \
then printf "\n$$GOFMT_OUT\n"; \
else echo "ok"; \
if [ -n "$$GOFMT_OUT" ]; then \
printf "\n$$GOFT_OUT\n"; \
exit 1; \
else printf "ok\n"; \
fi;

## Testing commands:
GOTEST = go test ./... -coverprofile=$(COVER_OUT) \
-covermode=atomic \
-timeout=$(TEST_TIMEOUT)
test:
@echo "Testing:"
@printf "Testing:\n"
@$(GOTEST)
test-v:
@echo "Testing (verbose):"
@printf "Testing (verbose):\n"
@$(GOTEST) -v

GOTEST_RACE = $(GOTEST) -race
test-race:
@echo "Testing (race):"
@$(GOTEST) -race
@printf "Testing (race):\n"
@$(GOTEST_RACE)
test-race-v:
@printf "Testing (race, verbose):\n"
@$(GOTEST_RACE) -v

GOBENCH = $(GOTEST) ./... -run=^$ -bench=. -benchmem
bench:
@echo "Benchmarking..."
@go test ./... -run=^$ -bench=. -benchmem
@printf "Benchmarking:\n"
@$(GOBENCH)
bench-v:
@printf "Benchmarking (verbose):\n"
@$(GOBENCH) -v
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ sports the following benchmark:

## Integration

`dgen` is a wrapper around an internal library, `throughput`, which contains
the real repeating and buffering logic. To create a program that is able to
use `dgen`'s string dumping algorithm, simply import `throughput`:
`dgen` is a thin wrapper around an internal library, `throughput`, which
contains the actual repeating and buffering logic. To create a program with
`dgen`'s string dumping capabilities, simply import `throughput`:

```go
import (
Expand All @@ -76,13 +76,13 @@ import (

func main() {
const (
in = "test string "
repstr = "test string "
reps = 5000
bufsize = 3000
bufsize = throughput.RecommendedBufSize
)

// Dump "test string " 5000 times into os.Stdout.
throughput.Dump(in, reps, bufsize, os.Stdout)
throughput.Dump(repstr, reps, bufsize, os.Stdout)
}
```

Expand Down
2 changes: 1 addition & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func parseArgs(args []string) (str string, reps int) {

str = args[0]
if nargs == 1 {
return str, DefaultReps
return str, defaultReps
}

repstr := args[1]
Expand Down
24 changes: 14 additions & 10 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ import (
"log"
)

/////////////////////////////
// Configurable constants
/////////////////////////////
func init() {
// Only write the log message to os.Stderr.
log.SetFlags(0)
}

const (
// DefaultReps is the default number of repeats, used if not otherwise
// defaultReps is the default number of repeats, used if not otherwise
// specified.
DefaultReps = 10
defaultReps = 10
)

var (
// Presets is a map of string identifiers to repeat counts. Identifiers
// presets is a map of string identifiers to repeat counts. Identifiers
// correspond to various messaging services.
Presets = map[string]uint{
"fb": 5000, "rpost": 40000, "rcomment": 10000, "rmsg": 10000,
"twitter": 280,
presets = map[string]uint{
"fb": 5000,
"rpost": 40000,
"rcomment": 10000,
"rmsg": 10000,
"twitter": 280,
}
)

func parsePreset(id string) int {
p, ok := Presets[id]
p, ok := presets[id]
if !ok {
log.Fatalf("Could not find preset: %s", id)
}
Expand Down
9 changes: 0 additions & 9 deletions log.go

This file was deleted.

22 changes: 9 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@ import (
"os"
)

func init() {
configureLog()
}
// out is the io.ReadWriter that dgen will write to.
var out io.ReadWriter = os.Stdout

func main() {
args := parseFlags()
str, reps := parseArgs(args)

// Set up output device and buffer size.
// Set up flags and buffer size.
var (
out io.ReadWriter = os.Stdout
bufsize = throughput.RecommendedBufSize
args = parseFlags()
str, reps = parseArgs(args)
bufsize = throughput.RecommendedBufSize
)

if Opts.Copy {
out = new(bytes.Buffer)
// Disallow buffering when using clipboard.
bufsize = 0
bufsize = 0 // disallow buffering when using clipboard
}

n, err := throughput.Dump(str, reps, bufsize, out)
Expand All @@ -39,8 +36,7 @@ func main() {
board.ReadFrom(out)
}

// If wrote to os.Sdout...
if !Opts.Copy {
if !Opts.Copy { // if wrote to os.Stdout
hasnl := hasTrailingNewline(str)

// Ensure that if extra info is about to be produced, there are at least two
Expand Down
File renamed without changes.
29 changes: 0 additions & 29 deletions main_darwin_test.go

This file was deleted.

Loading

0 comments on commit 55a0b32

Please sign in to comment.