4253 - support running just a single C test

We've had this ability for Mu scenarios forever.
This commit is contained in:
Kartik Agaram 2018-06-06 09:02:40 -07:00
parent 8f97725d00
commit 53172ce13a
7 changed files with 24 additions and 1 deletions

View File

@ -15,6 +15,9 @@ typedef void (*test_fn)(void);
const test_fn Tests[] = {
#include "test_list" // auto-generated; see 'build*' scripts
};
const string Test_names[] = {
#include "test_name_list"
};
:(before "End Globals")
bool Run_tests = false;
@ -82,5 +85,18 @@ void run_test(size_t i) {
// End Test Teardown
}
//: Convenience: run a single test
:(after "Test Runs")
string maybe_single_test_to_run = argv[argc-1];
if (!starts_with(maybe_single_test_to_run, "test_"))
maybe_single_test_to_run.insert(0, "test_");
for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) {
if (Test_names[i] == maybe_single_test_to_run) {
run_test(i);
if (Passed) cerr << ".\n";
return 0;
}
}
:(before "End Includes")
#include <stdlib.h>

1
build0
View File

@ -38,6 +38,7 @@ cd ..
grep -h "^[^[:space:]#].*) {$" mu.cc |grep -v ":.*(" |sed 's/ {.*/;/' > function_list
# auto-generate list of tests to run
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/\1,/' > test_list
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/"\1",/' > test_name_list
g++ -g -O2 mu.cc termbox/libtermbox.a -o mu_bin
cat [0-9]*.mu > core.mu

1
build1
View File

@ -57,6 +57,7 @@ LAYERS=$(./enumerate/enumerate --until $UNTIL_LAYER |grep '\.cc$')
grep -h "^[^[:space:]#].*) {$" mu.cc |grep -v ":.*(" |sed 's/ {.*/;/' > function_list
# auto-generate list of tests to run
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/\1,/' > test_list
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/"\1",/' > test_name_list
$CXX $CFLAGS mu.cc termbox/libtermbox.a -o mu_bin
## [0-9]*.mu -> core.mu

1
build2
View File

@ -125,6 +125,7 @@ mkdir -p .build
grep -h "^[^[:space:]#].*) {$" mu.cc |grep -v ":.*(" |sed 's/ {.*/;/' |update .build/function_list
# auto-generate list of tests to run
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/\1,/' |update .build/test_list
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/"\1",/' |update .build/test_name_list
mkdir -p .build/termbox
update_cp termbox/termbox.h .build/termbox

1
build3
View File

@ -150,6 +150,7 @@ mkdir -p .build
grep -h "^[^[:space:]#].*) {$" mu.cc |grep -v ":.*(" |sed 's/ {.*/;/' |update .build/function_list
# auto-generate list of tests to run
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/\1,/' |update .build/test_list
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/"\1",/' |update .build/test_name_list
mkdir -p .build/termbox
update_cp termbox/termbox.h .build/termbox

1
build4
View File

@ -193,6 +193,7 @@ mkdir -p .build
grep -h "^[^[:space:]#].*) {$" mu.cc |grep -v ":.*(" |sed 's/ {.*/;/' |update .build/function_list
# auto-generate list of tests to run
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/\1,/' |update .build/test_list
grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/"\1",/' |update .build/test_name_list
mkdir -p .build/termbox
update_cp termbox/termbox.h .build/termbox

View File

@ -1,7 +1,9 @@
#!/bin/sh
# Run tests for just a subset of layers.
#
# Usage:
# build_and_test_until [file prefix] [test name]
# Provide the second arg to run just a single (Mu) scenario.
# Provide the second arg to run just a single test.
set -e
# clean previous builds if they were building until a different layer