diff --git a/.travis.yml b/.travis.yml index 04d3ba9..cb5cef5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: d sudo: false +before_install: + - sudo apt-get install jq + matrix: include: - d: dmd-2.064.2 diff --git a/source/dub/dub.d b/source/dub/dub.d index 77abea4..31eb84e 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -422,27 +422,22 @@ write(dst.toPrettyString()); } - private void listPaths(string methodName)(BuildPlatform platform, string config) + void listImportPaths(BuildPlatform platform, string config) { - string[] importPaths; - - __traits(getMember, m_project, methodName)(importPaths, platform, config); - import std.stdio; - foreach(path; importPaths) { + foreach(path; m_project.listImportPaths(platform, config)) { writeln(path); } } - void listImportPaths(BuildPlatform platform, string config) - { - listPaths!"listImportPaths"(platform, config); - } - void listStringImportPaths(BuildPlatform platform, string config) { - listPaths!"listStringImportPaths"(platform, config); + import std.stdio; + + foreach(path; m_project.listStringImportPaths(platform, config)) { + writeln(path); + } } /// Cleans intermediate/cache files of the given package diff --git a/source/dub/project.d b/source/dub/project.d index a5bb2cc..34b0dc6 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -582,11 +582,13 @@ } } - private void listPaths(string attributeName)(ref string[] list, BuildPlatform platform, string config) + private string[] listPaths(string attributeName)(BuildPlatform platform, string config) { + import std.path : buildPath, dirSeparator; + auto configs = getPackageConfigs(platform, config); - import std.path : buildPath, dirSeparator; + string[] list; auto fullPackagePaths(Package pack) { // Return full paths for the import paths, making sure a @@ -605,19 +607,20 @@ list ~= path; } } + + return list; } /// Outputs the import paths for the project, including its dependencies. - void listImportPaths(ref string[] list, BuildPlatform platform, string config) + string [] listImportPaths(BuildPlatform platform, string config) { - listPaths!"importPaths"(list, platform, config); - + return listPaths!"importPaths"(platform, config); } /// Outputs the string import paths for the project, including its dependencies. - void listStringImportPaths(ref string[] list, BuildPlatform platform, string config) + string[] listStringImportPaths(BuildPlatform platform, string config) { - listPaths!"stringImportPaths"(list, platform, config); + return listPaths!"stringImportPaths"(platform, config); } void saveSelections() diff --git a/test/4-describe-import-paths.sh b/test/4-describe-import-paths.sh index 19e66f9..b896daf 100755 --- a/test/4-describe-import-paths.sh +++ b/test/4-describe-import-paths.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e -o pipefail + cd "$CURR_DIR"/describe-project temp_file=`mktemp` @@ -8,10 +10,9 @@ rm $temp_file } -$DUB describe --compiler=$COMPILER --import-paths > "$temp_file" +trap cleanup EXIT -if (( $? )); then - cleanup +if ! $DUB describe --compiler=$COMPILER --import-paths > "$temp_file"; then die 'Printing import paths failed!' fi @@ -21,9 +22,6 @@ echo "$CURR_DIR/describe-dependency-2/some-path/" >> "$CURR_DIR/expected-import-path-output" if ! diff "$CURR_DIR"/expected-import-path-output "$temp_file"; then - cleanup die 'The import paths did not match the expected output!' fi -cleanup -exit 0 diff --git a/test/4-describe-json.sh b/test/4-describe-json.sh index 254ac84..2969635 100755 --- a/test/4-describe-json.sh +++ b/test/4-describe-json.sh @@ -1,11 +1,34 @@ #!/bin/bash +set -e -o pipefail + cd "$CURR_DIR"/describe-project -$DUB describe --compiler=$COMPILER > /dev/null +temp_file=`mktemp` -if (( $? )); then +function cleanup { + rm $temp_file +} + +trap cleanup EXIT + +if ! $DUB describe --compiler=$COMPILER > "$temp_file"; then die 'Printing describe JSON failed!' fi -exit 0 +declare -A expr_map + +expr_map[description]='A test describe project' +expr_map[name]='describe-project' +expr_map[targetType]='sourceLibrary' +expr_map['authors[0]']='nobody' + +for expression in "${!expr_map[@]}"; do + expected="${expr_map[$expression]}" + + actual=`jq --raw-output '.packages[0].'"$expression" "$temp_file"` + + if [[ "$actual" != "$expected" ]]; then + die "The value for $expression was wrong in the describe output!" + fi +done diff --git a/test/4-describe-string-importh-paths.sh b/test/4-describe-string-importh-paths.sh index 184b9ad..790af85 100755 --- a/test/4-describe-string-importh-paths.sh +++ b/test/4-describe-string-importh-paths.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e -o pipefail + cd "$CURR_DIR"/describe-project temp_file=`mktemp` @@ -8,10 +10,9 @@ rm $temp_file } -$DUB describe --compiler=$COMPILER --string-import-paths > "$temp_file" +trap cleanup EXIT -if (( $? )); then - cleanup +if ! $DUB describe --compiler=$COMPILER --string-import-paths > "$temp_file"; then die 'Printing string import paths failed!' fi @@ -20,10 +21,6 @@ echo "$CURR_DIR/describe-dependency-2/some-extra-string-import-path/" >> "$CURR_DIR/expected-string-import-path-output" if ! diff "$CURR_DIR"/expected-string-import-path-output "$temp_file"; then - cleanup die 'The string import paths did not match the expected output!' fi -cleanup -exit 0 -