Skip to content

Commit

Permalink
fixed a bug with DFLAGS environment variable and cached generated uni…
Browse files Browse the repository at this point in the history
…ttest
  • Loading branch information
foerdi authored and Geod24 committed Mar 9, 2021
1 parent 5dd37ec commit a19e02d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/dub/dub.d
Expand Up @@ -692,10 +692,10 @@ class Dub {
mkdirRecurse(mainfile.parentPath.toNativeString());

bool regenerateMainFile = settings.force || !existsFile(mainfile);

auto escapedMainFile = mainfile.toNativeString().replace("$", "$$");
// generate main file
tcinfo.sourceFiles[""] ~= mainfile.toNativeString();
tcinfo.mainSourceFile = mainfile.toNativeString();
tcinfo.sourceFiles[""] ~= escapedMainFile;
tcinfo.mainSourceFile = escapedMainFile;

if (!m_dryRun && regenerateMainFile) {
auto fil = openFile(mainfile, FileMode.createTrunc);
Expand Down
39 changes: 39 additions & 0 deletions test/cache-generated-test-config.sh
Expand Up @@ -4,6 +4,7 @@
cd ${CURR_DIR}/cache-generated-test-config
rm -rf .dub

## default test
${DUB} test --compiler=${DC}

STAT="stat -c '%Y'"
Expand All @@ -21,4 +22,42 @@ MAIN_FILES_COUNT=$(ls .dub/code/*dub_test_root.d | wc -l)
[ "$EXECUTABLE_TIME" != "$(${STAT} cache-generated-test-config-test-library)" ] && die $LINENO 'The executable has been rebuilt'
[ "$MAIN_TIME" != "$(${STAT} "$(ls .dub/code/*dub_test_root.d | head -n1)")" ] && die $LINENO 'The test main file has been rebuilt'

## test with empty DFLAGS environment variable
DFLAGS="" ${DUB} test --compiler=${DC}

STAT="stat -c '%Y'"
[[ "$OSTYPE" == "darwin"* ]] && STAT="stat -f '%m' -t '%Y'"

EXECUTABLE_TIME="$(${STAT} cache-generated-test-config-test-library)"
[ -z "$EXECUTABLE_TIME" ] && die $LINENO 'no EXECUTABLE_TIME was found'
MAIN_TIME="$(${STAT} "$(ls .dub/code/*-\$DFLAGS-*dub_test_root.d)")"
[ -z "$MAIN_TIME" ] && die $LINENO 'no MAIN_TIME was found'

DFLAGS="" ${DUB} test --compiler=${DC}
MAIN_FILES_COUNT=$(ls .dub/code/*-\$DFLAGS-*dub_test_root.d | wc -l)

[ $MAIN_FILES_COUNT -ne 1 ] && die $LINENO 'DUB generated more then one main file'
[ "$EXECUTABLE_TIME" != "$(${STAT} cache-generated-test-config-test-library)" ] && die $LINENO 'The executable has been rebuilt'
[ "$MAIN_TIME" != "$(${STAT} "$(ls .dub/code/*-\$DFLAGS-*dub_test_root.d | head -n1)")" ] && die $LINENO 'The test main file has been rebuilt'

## test with DFLAGS environment variable
DFLAGS="-g" ${DUB} test --compiler=${DC}

STAT="stat -c '%Y'"
[[ "$OSTYPE" == "darwin"* ]] && STAT="stat -f '%m' -t '%Y'"

EXECUTABLE_TIME="$(${STAT} cache-generated-test-config-test-library)"
[ -z "$EXECUTABLE_TIME" ] && die $LINENO 'no EXECUTABLE_TIME was found'
MAIN_TIME="$(${STAT} "$(ls .dub/code/*-\$DFLAGS-*dub_test_root.d)")"
[ -z "$MAIN_TIME" ] && die $LINENO 'no MAIN_TIME was found'

DFLAGS="-g" ${DUB} test --compiler=${DC}
MAIN_FILES_COUNT=$(ls .dub/code/*-\$DFLAGS-*dub_test_root.d | wc -l)

[ $MAIN_FILES_COUNT -ne 1 ] && die $LINENO 'DUB generated more then one main file'
[ "$EXECUTABLE_TIME" != "$(${STAT} cache-generated-test-config-test-library)" ] && die $LINENO 'The executable has been rebuilt'
[ "$MAIN_TIME" != "$(${STAT} "$(ls .dub/code/*-\$DFLAGS-*dub_test_root.d | head -n1)")" ] && die $LINENO 'The test main file has been rebuilt'



exit 0

0 comments on commit a19e02d

Please sign in to comment.