This repository contains an attempt to implement smoke-testing of a CLI application. The application (xtractor) itself is simple:
Given input data in the form TIMESTAMP, VALUE and number of outputs X, it extracts the TIMESTAMPs of the X input data entries
with greatest VALUE. Input data could be supplied via file or via stdin.
The focus is on testing the application, both with unit tests as well as smoke-tests of the resulting binary (testing the user interface). Bazel is used to resolve the external dependencies and provide a clean and cacheable implementation.
Requirements:
- C++17
The code was tested on the following system:
Ubuntu 20.04.1 LTSg++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0bazel 4.1.0(it's highly recommended to use bazel!)
Bazel builds automatically before running/testing.
Run the main target and provide required arguments to the binary after the double-dash (--). For input via filename (path to data must be absolute):
bazel run //xtractor:main -- 3 $(pwd)/xtractor/testdata/sample_data.txtFor input via stdin, use --run_under to prepend a command:
bazel run //xtractor:main --run_under="cat $(pwd)/xtractor/testdata/sample_data.txt |" -- 3Run all tests via
bazel test //...Or run tests individually via
bazel test //xtractor:unit_tests
bazel test //xtractor:smoke_testsBuild from the workspace root (the directory that contains this README.md) and provide the correct include path for headers:
g++ -std=c++17 -I$(pwd) xtractor/main.cppCall the compiled binary (e.g. a.out) with at least one parameter (size X). Data input must be provided either via stdin or as filename:
./a.out 3 xtractor/testdata/sample_data.txtcat xtractor/testdata/sample_data.txt | ./a.out 3Help is shown when running without parameters:
./a.outTests have some dependencies (e.g. GoogleTest for the C++ unit tests, or assert.sh for the shell smoke-tests). Bazel will fetch these automatically (see above). In the traditional way, these dependencies have to be provided manually.