<commit_before><commit_msg>Add test for add-path based package selection.<commit_after>#!/usr/bin/env bash

. $(dirname ${BASH_SOURCE[0]})/common.sh

TMPDIR=$CURR_DIR/tmp-add-path

PACK_PATH="$CURR_DIR"/issue2262-exact-cached-version-match

# make sure that there are no left-over selections files or temp directory
rm -f $PACK_PATH/dub.selections.json
rm -rf $TMPDIR

# make sure that there are no cached versions of the dependency
$DUB remove gitcompatibledubpackage@* -n || true

# build normally, should select 1.0.4
if ! ${DUB} build --root $PACK_PATH | grep "gitcompatibledubpackage 1\.0\.4:"; then
    die $LINENO 'The initial build failed.'
fi

# clone gitcompatibledubpackage and check out 1.0.4+commit.2.ccb31bf
mkdir $TMPDIR
$DUB add-path $TMPDIR
cd $TMPDIR
git clone https://github.com/dlang-community/gitcompatibledubpackage.git
cd gitcompatibledubpackage
git checkout -q ccb31bf6a655437176ec02e04c2305a8c7c90d67
cd ../..

if ! $DUB list | grep "gitcompatibledubpackage 1\.0\.4+commit.2.gccb31bf"; then
    $DUB remove-path $TMPDIR
    die $LINENO 'Cloned package was not found in search path'
fi

# should pick up the cloned package instead of the cached one now
if ! ${DUB} build --root $PACK_PATH | grep "gitcompatibledubpackage 1\.0\.4+commit.2.gccb31bf:"; then
    $DUB remove-path $TMPDIR
    die $LINENO 'Did not pick up the add-path package.'
fi

# clean up
$DUB remove-path $TMPDIR
rm -f $PACK_PATH/dub.selections.json
rm -rf $TMPDIR
{'fraction_non_alphanumeric': 0.11065292096219931, 'fraction_numerical': 0.037800687285223365, 'mean_word_length': 4.294545454545455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4717695', 'n_tokens_mistral': 556, 'n_tokens_neox': 520, 'n_words': 156}