diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/assert.source.sh | 15 | ||||
| -rw-r--r-- | packages/atomfeed.source.sh | 3 | ||||
| -rw-r--r-- | packages/gemfeed.source.sh | 5 | ||||
| -rw-r--r-- | packages/generate.source.sh | 4 | ||||
| -rw-r--r-- | packages/html.source.sh | 2 | ||||
| -rw-r--r-- | packages/md.source.sh | 2 |
6 files changed, 25 insertions, 6 deletions
diff --git a/packages/assert.source.sh b/packages/assert.source.sh index c3ad0a6a..5d3a5c5d 100644 --- a/packages/assert.source.sh +++ b/packages/assert.source.sh @@ -30,3 +30,18 @@ assert::not_empty () { log VERBOSE "Result in $callee as expected not empty" } + +# Unit test for whether a given string matches a regex. +assert::matches () { + local -r name="$1"; shift + local -r content="$1"; shift + local -r regex="$1"; shift + local -r callee=${FUNCNAME[1]} + + if ! $GREP -q -E "$regex" <<< "$content"; then + log ERROR "In $callee expected '$name' to match '$regex'" + exit 2 + fi + + log VERBOSE "Matching in $callee as expected" +} diff --git a/packages/atomfeed.source.sh b/packages/atomfeed.source.sh index 6d5a8f47..f17b00fb 100644 --- a/packages/atomfeed.source.sh +++ b/packages/atomfeed.source.sh @@ -6,7 +6,7 @@ atomfeed::meta () { log VERBOSE "Generating meta info for post $gmi_file_path" local is_draft=no - if grep -E -q '\.draft\.meta$' <<< "$meta_file"; then + if $GREP -E -q '\.draft\.meta$' <<< "$meta_file"; then is_draft=yes fi @@ -75,6 +75,7 @@ ATOMHEADER while read -r gmi_file; do # Load cached meta information about the post. source <(atomfeed::meta "$gemfeed_dir/$gmi_file") + # Get HTML content for the feed local content="$(atomfeed::content "$gemfeed_dir/$gmi_file")" diff --git a/packages/gemfeed.source.sh b/packages/gemfeed.source.sh index 182d6eb0..33ea0c8d 100644 --- a/packages/gemfeed.source.sh +++ b/packages/gemfeed.source.sh @@ -4,7 +4,10 @@ gemfeed::get_posts () { local -r gmi_pattern='^[0-9]{4}-[0-9]{2}-[0-9]{2}-.*\.gmi$' local -r draft_pattern='\.draft\.gmi$' - ls "$gemfeed_dir" | grep -E "$gmi_pattern" | grep -E -v "$draft_pattern" | sort -r + ls "$gemfeed_dir" | + $GREP -E "$gmi_pattern" | + $GREP -E -v "$draft_pattern" | + sort -r } # Add the links from gemfeed/index.gmi to the main index site. diff --git a/packages/generate.source.sh b/packages/generate.source.sh index 248fe6c4..83bf69ee 100644 --- a/packages/generate.source.sh +++ b/packages/generate.source.sh @@ -15,7 +15,7 @@ generate::make_link () { fi done < <(echo "$line" | tr ' ' '\n') - if grep -E -q "$IMAGE_PATTERN" <<< "$link"; then + if $GREP -E -q "$IMAGE_PATTERN" <<< "$link"; then if [[ "$what" == md ]]; then md::make_img "$link" "$descr" else @@ -115,7 +115,7 @@ generate::fromgmi () { for format in "$@"; do generate::fromgmi_add_docs "$src" "$format" done - done < <(find "$CONTENT_DIR/gemtext" -type f | grep -E -v '(.gmi|atom.xml|.tmp)$') + done < <(find "$CONTENT_DIR/gemtext" -type f | $GREP -E -v '(.gmi|atom.xml|.tmp)$') log INFO "Added $num_doc_files other documents to each of $*" diff --git a/packages/html.source.sh b/packages/html.source.sh index cc79e612..5a292f1c 100644 --- a/packages/html.source.sh +++ b/packages/html.source.sh @@ -46,7 +46,7 @@ html::make_link () { local link="$1"; shift local descr="$1"; shift - grep -F -q '://' <<< "$link" || link=${link/.gmi/.html} + $GREP -F -q '://' <<< "$link" || link=${link/.gmi/.html} test -z "$descr" && descr="$link" echo "<a class=\"textlink\" href=\"$link\">$descr</a><br />" } diff --git a/packages/md.source.sh b/packages/md.source.sh index 2f85b3c2..957b9cf3 100644 --- a/packages/md.source.sh +++ b/packages/md.source.sh @@ -15,7 +15,7 @@ md::make_link () { local link="$1"; shift local descr="$1"; shift - grep -F -q '://' <<< "$link" || link=${link/.gmi/.md} + $GREP -F -q '://' <<< "$link" || link=${link/.gmi/.md} test -z "$descr" && descr="$link" echo "[$descr]($link) " |
