diff --git a/.appveyor.yml b/.appveyor.yml index 5c138b94..2bf46ade 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -19,8 +19,8 @@ build_script: copy "build\release\bin\*" "${dir}\build\release\bin" copy -recurse "build\LLVM-5.0.1-win64\lib\clang\5.0.1\include" "${dir}\build\release\lib\LLVM-5.0.1-win64\lib\clang\5.0.1\" 7z a -tzip "C:\projects\cquery\${dir}.zip" "${dir}" - - build\release\bin\cquery --log-all-to-stderr --test-unit - - build\release\bin\cquery --log-all-to-stderr --test-index + - build\release\bin\cquery --ci --log-all-to-stderr --test-unit + - build\release\bin\cquery --ci --log-all-to-stderr --test-index artifacts: - path: 'cquery-*.zip' diff --git a/.travis.yml b/.travis.yml index 246ef67d..a0940b4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -195,8 +195,8 @@ before_script: script: - travis_retry ./waf configure - ./waf build - - ./build/release/bin/cquery --log-all-to-stderr --test-unit - - ./build/release/bin/cquery --log-all-to-stderr --test-index + - ./build/release/bin/cquery --ci --log-all-to-stderr --test-unit + - ./build/release/bin/cquery --ci --log-all-to-stderr --test-index notifications: email: false diff --git a/src/command_line.cc b/src/command_line.cc index 10be4cd2..5178a6dc 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -430,7 +430,8 @@ int main(int argc, char** argv) { if (HasOption(options, "--test-index")) { print_help = false; - RunIndexTests(options["--test-index"]); + if (!RunIndexTests(options["--test-index"], !HasOption(options, "--ci"))) + return -1; } if (HasOption(options, "--enable-comments")) { @@ -483,6 +484,9 @@ Command line options: If true, cquery will wait for an '[Enter]' before exiting. Useful on windows. --help Print this help information. + --ci Prevents tests from prompting the user for input. Used for + continuous integration so it can fail faster instead of timing + out. Configuration: When opening up a directory, cquery will look for a compile_commands.json file diff --git a/src/test.cc b/src/test.cc index cb6d7ba5..4a5f4802 100644 --- a/src/test.cc +++ b/src/test.cc @@ -108,7 +108,7 @@ IndexFile* FindDbForPathEnding( return nullptr; } -void RunIndexTests(const std::string& filter_path) { +bool RunIndexTests(const std::string& filter_path, bool enable_update) { SetTestOutputMode(); // Index tests change based on the version of clang used. @@ -121,6 +121,7 @@ void RunIndexTests(const std::string& filter_path) { exit(1); } + bool success = true; bool update_all = false; ClangIndex index; @@ -226,28 +227,33 @@ void RunIndexTests(const std::string& filter_path) { if (actual == expected) { // std::cout << "[PASSED] " << path << std::endl; } else { + success = false; DiffDocuments(path, expected_path, expected, actual); std::cout << std::endl; std::cout << std::endl; - std::cout + if (enable_update) { + std::cout << "[Enter to continue - type u to update test, a to update all]"; - char c = 'u'; - if (!update_all) { - c = (char)std::cin.get(); - std::cin.get(); - } + char c = 'u'; + if (!update_all) { + c = (char)std::cin.get(); + std::cin.get(); + } - if (c == 'a') - update_all = true; + if (c == 'a') + update_all = true; - if (update_all || c == 'u') { - // Note: we use |entry.second| instead of |expected_output| because - // |expected_output| has had text replacements applied. - UpdateTestExpectation(path, entry.second, ToString(actual) + "\n"); + if (update_all || c == 'u') { + // Note: we use |entry.second| instead of |expected_output| because + // |expected_output| has had text replacements applied. + UpdateTestExpectation(path, entry.second, ToString(actual) + "\n"); + } } } } } + + return success; } // TODO: ctor/dtor, copy ctor diff --git a/src/test.h b/src/test.h index 3e88f02c..294d1ff9 100644 --- a/src/test.h +++ b/src/test.h @@ -2,4 +2,4 @@ #include -void RunIndexTests(const std::string& filter_path); +bool RunIndexTests(const std::string& filter_path, bool enable_update);