Skip to content

Commit

Permalink
include dead code elimination check as part of standard testing
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Mar 25, 2016
1 parent a54f6aa commit 4a93a95
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 24 deletions.
57 changes: 33 additions & 24 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
:clean-targets ^{:protect false} ["target"
"test/resources/_compiled"]

:plugins [[lein-cljsbuild "1.1.2"]]
:plugins [[lein-cljsbuild "1.1.3"]
[lein-shell "0.5.0"]]

:hooks [leiningen.cljsbuild]

:source-paths ["src"]
:test-paths ["test/src/test"]

:aliases {"test" ["with-profile" "test" "test"]}

:cljsbuild {:builds {}} ; prevent https://github.com/emezeske/lein-cljsbuild/issues/413

:profiles {:devel
Expand All @@ -34,24 +34,33 @@
:optimizations :none
:source-map true}}}}}

:test
{:cljsbuild {:builds {:tests
{:source-paths ["src"
"test/src/tests"]
:compiler {:output-to "test/resources/_compiled/tests/build.js"
:output-dir "test/resources/_compiled/tests"
:asset-path "_compiled/tests"
:main devtools.runner
:optimizations :none
:pretty-print true
:source-map true}}
:dead-code-elimination
{:source-paths ["src"
"test/src/dead-code-elimination"]
:compiler {:output-to "test/resources/_compiled/dead-code-elimination/build.js"
:output-dir "test/resources/_compiled/dead-code-elimination"
:asset-path "_compiled/dead-code-elimination"
:closure-defines {"goog.DEBUG" false}
:pseudo-names true
:optimizations :advanced}}}
:test-commands {"unit" ["phantomjs" "test/resources/phantom.js" "test/resources/runner.html"]}}}})
:testing
{:cljsbuild {:builds {:tests
{:source-paths ["src"
"test/src/tests"]
:compiler {:output-to "test/resources/_compiled/tests/build.js"
:output-dir "test/resources/_compiled/tests"
:asset-path "_compiled/tests"
:main devtools.runner
:optimizations :none
:pretty-print true
:source-map true}}
:dead-code-elimination
{:source-paths ["src"
"test/src/dead-code-elimination"]
:compiler {:output-to "test/resources/_compiled/dead-code-elimination/build.js"
:output-dir "test/resources/_compiled/dead-code-elimination"
:asset-path "_compiled/dead-code-elimination"
:closure-defines {"goog.DEBUG" false}
:pseudo-names true
:optimizations :advanced}}}}}}

:aliases {"test" ["do"
"test-phantom,"
"test-dead-code"]
"test-dead-code" ["do"
"with-profile" "+testing" "cljsbuild" "once" "dead-code-elimination,"
"shell" "test/scripts/dead-code-check.sh"]
"test-phantom" ["do"
"with-profile" "+testing" "cljsbuild" "once" "tests,"
"shell" "phantomjs" "test/resources/phantom.js" "test/resources/runner.html"]})
18 changes: 18 additions & 0 deletions test/scripts/dead-code-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# ensure that advanced build has no traces of devtools namespace references

set -e

COMPILED_PATH="test/resources/_compiled/dead-code-elimination/build.js"

STATS=`cat "$COMPILED_PATH" | perl -pe 's/(\\$|\\d+)\\$/\\1\\$\\n/g' | grep -o 'devtools\\$.*' | sort | uniq -c`

if [[ -z "$STATS" ]]; then
echo "Compiled file '$COMPILED_PATH' contains no traces of devtools (as expected)."
exit 0
else
echo "Compiled file '$COMPILED_PATH' contains symbols which were expected to be removed as a dead code during :advanced build"
echo "$STATS"
exit 1
fi

0 comments on commit 4a93a95

Please # to comment.