Skip to content

Commit

Permalink
Merge pull request #16 from moul/dev/moul/lowercase
Browse files Browse the repository at this point in the history
chore: improve tests
  • Loading branch information
moul committed Sep 25, 2022
2 parents dd4e480 + 30dd515 commit d354fbd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG VCS_REF
ARG VERSION

# build
FROM golang:1.16-alpine as builder
FROM golang:1.14-alpine as builder
RUN apk add --no-cache git gcc musl-dev make
ENV GO111MODULE=on
WORKDIR /go/src/moul.io/banner
Expand All @@ -14,7 +14,7 @@ COPY . ./
RUN make install

# minimalist runtime
FROM alpine:3.13
FROM alpine:3.11
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="banner" \
org.label-schema.description="" \
Expand Down
50 changes: 50 additions & 0 deletions banner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,56 @@ func ExampleInline() {
// end of banner
}

func ExampleInline_lowercase() {
fmt.Println("start of banner")
fmt.Println(banner.Inline("abcdefghij"))
fmt.Println(banner.Inline("klmnopqrst"))
fmt.Println(banner.Inline("uvwxyz"))
fmt.Println("end of banner")
// Output:
// start of banner
// _ _ __ _ _ _
// __ _ | |__ __ __| | ___ / _| __ _ | |_ (_) (_)
// / _` || '_ \/ _|/ _` |/ -_)| _|/ _` || ' \ | | | |
// \__,_||_.__/\__|\__,_|\___||_| \__, ||_||_||_| _/ |
// |___/ |__/
// _ _ _
// | |__| | _ __ _ _ ___ _ __ __ _ _ _ ___| |_
// | / /| || ' \ | ' \ / _ \| '_ \/ _` || '_|(_-<| _|
// |_\_\|_||_|_|_||_||_|\___/| .__/\__, ||_| /__/ \__|
// |_| |_|
// _ _ __ ____ __ ____ __ _ _ ___
// | || |\ V /\ V V /\ \ /| || ||_ /
// \_,_| \_/ \_/\_/ /_\_\ \_, |/__|
// |__/
// end of banner
}

func ExampleInline_uppercase() {
fmt.Println("start of banner")
fmt.Println(banner.Inline("ABCDEFGHIJ"))
fmt.Println(banner.Inline("KLMNOPQRST"))
fmt.Println(banner.Inline("UVWXYZ"))
fmt.Println("end of banner")
// Output:
// start of banner
// _ _ __ _ _ _
// __ _ | |__ __ __| | ___ / _| __ _ | |_ (_) (_)
// / _` || '_ \/ _|/ _` |/ -_)| _|/ _` || ' \ | | | |
// \__,_||_.__/\__|\__,_|\___||_| \__, ||_||_||_| _/ |
// |___/ |__/
// _ _ _
// | |__| | _ __ _ _ ___ _ __ __ _ _ _ ___| |_
// | / /| || ' \ | ' \ / _ \| '_ \/ _` || '_|(_-<| _|
// |_\_\|_||_|_|_||_||_|\___/| .__/\__, ||_| /__/ \__|
// |_| |_|
// _ _ __ ____ __ ____ __ _ _ ___
// | || |\ V /\ V V /\ \ /| || ||_ /
// \_,_| \_/ \_/\_/ /_\_\ \_, |/__|
// |__/
// end of banner
}

func TestInline(t *testing.T) {
tests := []struct {
input string
Expand Down
1 change: 1 addition & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

// message from the author:
//
// +--------------------------------------------------------------+
// | * * * ░░░░░░░░░░░░░░░░░░░░ Hello ░░░░░░░░░░░░░░░░░░░░░░░░░░|
// +--------------------------------------------------------------+
Expand Down
57 changes: 6 additions & 51 deletions rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ all: help
##

rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
check-program = $(foreach exec,$(1),$(if $(shell PATH="$(PATH)" which $(exec)),,$(error "No $(exec) in PATH")))

##
## rules.mk
Expand Down Expand Up @@ -73,31 +72,18 @@ GO_INSTALL_OPTS ?=
GO_TEST_OPTS ?= -test.timeout=30s
GOMOD_DIR ?= .
GOCOVERAGE_FILE ?= ./coverage.txt
GOTESTJSON_FILE ?= ./go-test.json
GOBUILDLOG_FILE ?= ./go-build.log
GOINSTALLLOG_FILE ?= ./go-install.log

ifdef GOBINS
.PHONY: go.install
go.install:
ifeq ($(CI),true)
@rm -f /tmp/goinstall.log
@set -e; for dir in $(GOBINS); do ( set -xe; \
cd $$dir; \
$(GO) install -v $(GO_INSTALL_OPTS) .; \
); done 2>&1 | tee $(GOINSTALLLOG_FILE)

else
@set -e; for dir in $(GOBINS); do ( set -xe; \
cd $$dir; \
$(GO) install $(GO_INSTALL_OPTS) .; \
); done
endif
INSTALL_STEPS += go.install

.PHONY: go.release
go.release:
$(call check-program, goreleaser)
goreleaser --snapshot --skip-publish --rm-dist
@echo -n "Do you want to release? [y/N] " && read ans && \
if [ $${ans:-N} = y ]; then set -xe; goreleaser --rm-dist; fi
Expand All @@ -106,29 +92,15 @@ endif

.PHONY: go.unittest
go.unittest:
ifeq ($(CI),true)
@echo "mode: atomic" > /tmp/gocoverage
@rm -f $(GOTESTJSON_FILE)
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do (set -e; (set -euf pipefail; \
cd $$dir; \
($(GO) test ./... $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race -json | tee -a $(GOTESTJSON_FILE) 3>&1 1>&2 2>&3 | tee -a $(GOBUILDLOG_FILE); \
); \
if [ -f /tmp/profile.out ]; then \
cat /tmp/profile.out | sed "/mode: atomic/d" >> /tmp/gocoverage; \
rm -f /tmp/profile.out; \
fi)); done
@mv /tmp/gocoverage $(GOCOVERAGE_FILE)
else
@echo "mode: atomic" > /tmp/gocoverage
@set -e; for dir in `find $(GOMOD_DIR) -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq`; do (set -e; (set -xe; \
cd $$dir; \
$(GO) test ./... $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race); \
$(GO) test $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...); \
if [ -f /tmp/profile.out ]; then \
cat /tmp/profile.out | sed "/mode: atomic/d" >> /tmp/gocoverage; \
rm -f /tmp/profile.out; \
fi); done
@mv /tmp/gocoverage $(GOCOVERAGE_FILE)
endif

.PHONY: go.checkdoc
go.checkdoc:
Expand Down Expand Up @@ -182,20 +154,6 @@ UNITTEST_STEPS += go.unittest
FMT_STEPS += go.fmt
endif

##
## Gitattributes
##

ifneq ($(wildcard .gitattributes),)
.PHONY: _linguist-ignored
_linguist-kept:
@git check-attr linguist-vendored $(shell git check-attr linguist-generated $(shell find . -type f | grep -v .git/) | grep unspecified | cut -d: -f1) | grep unspecified | cut -d: -f1 | sort

.PHONY: _linguist-kept
_linguist-ignored:
@git check-attr linguist-vendored linguist-ignored `find . -not -path './.git/*' -type f` | grep '\ set$$' | cut -d: -f1 | sort -u
endif

##
## Node
##
Expand All @@ -222,12 +180,6 @@ endif
## Docker
##

docker_build = docker build \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION=`git describe --tags --always` \
-t "$2" -f "$1" "$(dir $1)"

ifndef DOCKERFILE_PATH
DOCKERFILE_PATH = ./Dockerfile
endif
Expand All @@ -240,8 +192,11 @@ ifdef DOCKER_IMAGE
ifneq ($(DOCKER_IMAGE),none)
.PHONY: docker.build
docker.build:
$(call check-program, docker)
$(call docker_build,$(DOCKERFILE_PATH),$(DOCKER_IMAGE))
docker build \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION=`git describe --tags --always` \
-t $(DOCKER_IMAGE) -f $(DOCKERFILE_PATH) $(dir $(DOCKERFILE_PATH))

BUILD_STEPS += docker.build
endif
Expand Down

0 comments on commit d354fbd

Please sign in to comment.