Skip to content

Commit

Permalink
Improve test
Browse files Browse the repository at this point in the history
- Bump up mrubyc-test which:
  - runs with Ruby 3.0.0!
  - adds `-O0 -g3` to make debug easier
- Dockerfile
  - uses ruby:3.0.0-slim image
  - makes cache working better
- Makefile
  - includes check_tag target which detects change of MRUBY_VERSION
    in mrblib/global.rb and automatically invokes `make setup_test`
  • Loading branch information
hasumikin committed Jan 12, 2021
1 parent ed8b710 commit 38f5e72
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 35 deletions.
38 changes: 28 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
from ruby:2.7.2-slim
from ruby:3.0.0-slim

RUN apt update && apt -y upgrade
RUN apt install -y bison make git gcc gcc-arm-linux-gnueabi qemu qemu-kvm qemu-system-arm
RUN apt install -y \
bison \
gcc \
gcc-arm-linux-gnueabi \
git \
make \
qemu \
qemu-kvm \
qemu-system-arm

RUN gem update --system

RUN git clone https://github.com/mruby/mruby /root/mruby
ARG MRUBY_TAG
RUN cd /root/mruby; git checkout $MRUBY_TAG; make
RUN useradd -m -u 1000 mrubyc
RUN mkdir /work && chown mrubyc /work

USER mrubyc

VOLUME /root/mrubyc
COPY Gemfile /root/mrubyc/
COPY Gemfile.lock /root/mrubyc/
WORKDIR /root/mrubyc
VOLUME /work/mrubyc
COPY --chown=mrubyc Gemfile /work/mrubyc/
COPY --chown=mrubyc Gemfile.lock /work/mrubyc/

USER root
WORKDIR /work/mrubyc
RUN bundle install

USER mrubyc
ENV CFLAGS="-DMRBC_USE_MATH=1 -DMAX_SYMBOLS_COUNT=500"
CMD ["bundle", "exec", "mrubyc-test", "-e", "100", "-p", "/root/mruby/build/host/bin/mrbc"]

RUN git clone https://github.com/mruby/mruby /work/mruby
ARG MRUBY_TAG
RUN cd /work/mruby; git fetch --prune; git checkout $MRUBY_TAG; make clean && make

CMD ["bundle", "exec", "mrubyc-test", "-e", "10", "-p", "/work/mruby/build/host/bin/mrbc"]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://rubygems.org"

gem "mrubyc-test", "~> 0.6"
gem "mrubyc-test", "~> 0.6.1"
27 changes: 13 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.3.4)
activesupport (6.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
concurrent-ruby (1.1.7)
i18n (1.8.5)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
minitest (5.14.2)
mrubyc-test (0.6.0)
minitest (5.14.3)
mrubyc-test (0.6.1)
activesupport (~> 6.0)
rufo (~> 0.12)
thor (~> 1.0)
rufo (0.12.0)
thor (1.0.1)
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
zeitwerk (2.4.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
zeitwerk (2.4.2)

PLATFORMS
ruby

DEPENDENCIES
mrubyc-test (~> 0.6)
mrubyc-test (~> 0.6.1)

BUNDLED WITH
2.1.4
2.2.5
31 changes: 21 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
# This file is distributed under BSD 3-Clause License.
#

# tag or branch name of mruby/mruby
MRUBY_TAG = `grep MRUBY_VERSION mrblib/global.rb | sed 's/MRUBY_VERSION *= *"\(.\+\)"/\1/'`
# MRUBY_TAG corresponds to tag or branch of mruby/mruby
MRUBY_TAG = $(shell grep MRUBY_VERSION mrblib/global.rb | sed 's/MRUBY_VERSION *= *"\(.\+\)"/\1/')

all: mrubyc_lib mrubyc_bin


mrubyc_lib:
cd mrblib ; $(MAKE) all
cd src ; $(MAKE) all
Expand Down Expand Up @@ -40,15 +39,27 @@ package: clean
rm -Rf pkg ;\
echo Done.

.PHONY: test setup_test
test:
docker run --mount type=bind,src=${PWD}/,dst=/root/mrubyc \
.PHONY: test setup_test check_tag

test: check_tag
docker run --mount type=bind,src=${PWD}/,dst=/work/mrubyc \
-e CFLAGS="-DMRBC_USE_MATH=1 -DMAX_SYMBOLS_COUNT=500 $(CFLAGS)" \
mrubyc/mrubyc-test bundle exec mrubyc-test \
mrubyc-dev bundle exec mrubyc-test \
--every=10 \
--mrbc-path=/root/mruby/build/host/bin/mrbc \
--mrbc-path=/work/mruby/build/host/bin/mrbc \
$(file)

setup_test:
check_tag:
$(eval CURRENT_MRUBY_TAG = $(shell docker run mrubyc-dev \
/bin/sh -c 'cd /work/mruby && git status | ruby -e"puts STDIN.first.split(\" \")[-1]"'))
@echo MRUBY_TAG=$(MRUBY_TAG)
docker build -t mrubyc/mrubyc-test --build-arg MRUBY_TAG=$(MRUBY_TAG) .
@echo CURRENT_MRUBY_TAG=$(CURRENT_MRUBY_TAG)
if test "$(CURRENT_MRUBY_TAG)" = "$(MRUBY_TAG)"; \
then \
echo 'Skip setup_test'; \
else \
make setup_test; \
fi

setup_test:
docker build -t mrubyc-dev --build-arg MRUBY_TAG=$(MRUBY_TAG) .

0 comments on commit 38f5e72

Please sign in to comment.