Skip to content

Commit f27640f

Browse files
committed
Speed up config tests
1 parent ca51588 commit f27640f

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

specs/Config.cram.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
~~~shell
44
# Use README.md for default config
55
$ cp $TESTDIR/../README.md readme.doco.md
6-
7-
# Ignore/null out all configuration for testing
8-
$ doco --
96
~~~
107

118
### File and Function Names
129

1310
Configuration is loaded using loco. Specifically, by searching for `*.doco.md`, `.doco`, or `docker-compose.yml` above the current directory. The loco script name is hardcoded to `doco`, so even if it's run via a symlink the function names for custom subcommands will still be `doco.subcommand-name`. User and site-level configs are also defined.
1411

1512
~~~shell
16-
$ declare -p LOCO_FILE LOCO_NAME LOCO_USER_CONFIG LOCO_SITE_CONFIG
13+
$ run-doco declare LOCO_FILE LOCO_NAME LOCO_USER_CONFIG LOCO_SITE_CONFIG
1714
declare -a LOCO_FILE=([0]="?*[-.]doco.md" [1]=".doco" [2]="docker-compose.yml")
1815
declare -- LOCO_NAME="doco"
1916
declare -- LOCO_USER_CONFIG="/*/.config/doco" (glob)
@@ -31,7 +28,7 @@ Either way, service targets are created for any services that don't already have
3128
~~~shell
3229
# COMPOSE_FILE is exported, pointing to the cache; DOCO_CONFIG is the same,
3330
# and COMPOSE_PATH_SEPARATOR is a line break
34-
$ declare -p COMPOSE_FILE DOCO_CONFIG COMPOSE_PATH_SEPARATOR
31+
$ run-doco declare COMPOSE_FILE DOCO_CONFIG COMPOSE_PATH_SEPARATOR
3532
declare -x COMPOSE_FILE="/*/Config.cram.md/.doco-cache.json" (glob)
3633
declare -- DOCO_CONFIG="/*/Config.cram.md/.doco-cache.json" (glob)
3734
declare -x COMPOSE_PATH_SEPARATOR="
@@ -41,7 +38,7 @@ Either way, service targets are created for any services that don't already have
4138
$ [[ readme.doco.md -ot .doco-cache.sh || readme.doco.md -nt .doco-cache.sh ]] || echo equal
4239
equal
4340
$ touch -r readme.doco.md savetime; touch readme.doco.md
44-
$ command doco --all
41+
$ run-doco --all
4542
example1
4643
$ [[ "$(stat -c %y readme.doco.md)" != "$(stat -c %y savetime)" ]] && echo changed
4744
changed
@@ -50,7 +47,7 @@ Either way, service targets are created for any services that don't already have
5047

5148
# There can be only one! ([.-]doco.md file, that is)
5249
$ touch another-doco.md
53-
$ command doco
50+
$ run-doco
5451
Multiple doco.md files in /*/Config.cram.md (glob)
5552
[64]
5653
$ rm another-doco.md
@@ -66,29 +63,29 @@ Either way, service targets are created for any services that don't already have
6663
> }
6764
> ' >.doco
6865
$ echo 'services: {t: {image: alpine, command: "bash -c echo test"}}' >docker-compose.yml
69-
$ COMPOSE_PROJECT_NAME=foo command doco dump
66+
$ COMPOSE_PROJECT_NAME=foo run-doco dump
7067
cleared!
7168
{"services":{"t":{"command":"bash -c echo test","image":"alpine"}}}
7269
declare -x COMPOSE_PROJECT_NAME=""
7370

7471
# Must be only one docker-compose.y{a,}ml
7572
$ touch docker-compose.yaml
76-
$ command doco dump
73+
$ run-doco dump
7774
Multiple docker-compose files in /*/Config.cram.md/t (glob)
7875
[64]
7976
$ rm docker-compose.yaml
8077

8178
# docker-compose.override.yml and docker-compose.override.yaml are included in COMPOSE_FILE
8279
$ echo 'doco.dump() { declare -p COMPOSE_FILE; }' >.doco
83-
$ command doco dump
80+
$ run-doco dump
8481
declare -x COMPOSE_FILE="/*/Config.cram.md/t/.doco-cache.json" (glob)
85-
$ touch docker-compose.override.yml; command doco dump
82+
$ touch docker-compose.override.yml; run-doco dump
8683
declare -x COMPOSE_FILE="/*/Config.cram.md/t/.doco-cache.json (glob)
8784
/*/Config.cram.md/t/docker-compose.override.yml" (glob)
88-
$ touch docker-compose.override.yaml; command doco dump
85+
$ touch docker-compose.override.yaml; run-doco dump
8986
Multiple docker-compose.override files in /*/Config.cram.md/t (glob)
9087
[64]
91-
$ rm docker-compose.override.yml; command doco dump
88+
$ rm docker-compose.override.yml; run-doco dump
9289
declare -x COMPOSE_FILE="/*/Config.cram.md/t/.doco-cache.json (glob)
9390
/*/Config.cram.md/t/docker-compose.override.yaml" (glob)
9491

@@ -104,7 +101,7 @@ Either way, service targets are created for any services that don't already have
104101
> event on "before_commands" declare -p __doco_target__2d_2dall
105102
> EOF
106103
107-
$ command doco t dump
104+
$ run-doco t dump
108105
hi!
109106
declare -ar __doco_target__2d_2dall=([0]="t")
110107
t
@@ -113,7 +110,7 @@ Either way, service targets are created for any services that don't already have
113110
# doco command(s) can't be run from config:
114111
115112
$ echo 'doco --all' >.doco
116-
$ command doco
113+
$ run-doco
117114
doco CLI cannot be used before the project spec is finalized
118115
[64]
119116

specs/cram-setup.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ echo '{"version": "2.1", "services": {"example1":{}}}' >docker-compose.yml
1313

1414
# Initialize doco in-process when run without other initialization
1515
doco() { unset -f doco; loco_main "$@"; }
16+
17+
# command to dump variables
18+
doco.declare() { declare -p "$@"; }
19+
20+
# Run uninitialized doco in a subprocess, with -e re-enabled
21+
run-doco() (
22+
set -e
23+
doco "$@"
24+
)

0 commit comments

Comments
 (0)