Minimum Viable Architecture
  • Book
  • Big Ideas
  • Chief Analytics Officer
  • Contact
  • Book
  • Big Ideas
  • Chief Analytics Officer
  • Contact

​Things under the covers

Bits and pieces of the big ideas

Simple makefile tests

9/10/2021

0 Comments

 
Getting a handle on testing requires you become comfortable writing test. The place to start is with the simplest test you can think of. Even though Make will notify you if a file is missing, learning how to write these simple test and to format useful output is a valuable skill to practice.
Helper variable for a timestamp:
​DTS = $(shell date +%Y-%m-%dT%H:%M:%S-%Z)
Test for a directory:
define test_dir
    # tests the directory in the <first dependency>
    if ! test -d $<; \
    then echo $(DTS)    [FAIL] - $< does not exist; \
    else true; fi
endef

ROOTDIR := $(shell pwd)
​
ROOTDIR: $(ROOTDIR)
    @$(test_dir)
Test for a file:
define test_file
    # tests the file in the <first dependency>
    if ! test -s $@; \
    then echo $(DTS)    [FAIL] - $@ does not exist; \
    else true; fi
endef

etc/sql/INFO_WEEKLY_TOP_SALES_RANK_002_load.sql:
    @$(test_file)
Test for a dependent file:

define test_dependent_file
    # tests the file in the <first dependency>
    if ! test -s $<; \
    then echo $(DTS)    [FAIL] - $< does not exist; \
    else true; fi
endef

SHELL := $(which bash)

SHELL: $(SHELL)
    @$(test_dependent_file)
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    Picture

    Brian McMillan

    Sweating the details and still looking at the big picture.

    Archives

    September 2021
    November 2015

    Categories

    All
    Policies

    RSS Feed

© COPYRIGHT 2015-2022. ALL RIGHTS RESERVED.