From 0941df7c53ba0b064050bb558a8f15fda06170aa Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Fri, 18 Nov 2016 14:31:24 +0100 Subject: [PATCH] Fixes diff --- .gitmodules | 3 -- Source/Program/CommandController.cpp | 3 +- Source/Program/CommandParser.cpp | 1 - Source/Program/Diagnostics.cpp | 3 +- Source/Program/Utils.cpp | 30 +++++++++--------- Source/TestFramework/Core.cpp | 31 +++++++++++-------- Source/TestFramework/ProjectTestRunner.cpp | 2 +- Source/Vendors/dtl | 1 - Tasks/AcceptBaseline.cpp | 2 +- Tasks/GenerateDiagnostics.cpp | 2 ++ .../Reference/Projects/DefaultHelp/stdout.out | 12 +++---- .../Projects/UnknownCommandOption/stdout.out | 1 + 12 files changed, 47 insertions(+), 44 deletions(-) delete mode 160000 Source/Vendors/dtl create mode 100644 Tests/Reference/Projects/UnknownCommandOption/stdout.out diff --git a/.gitmodules b/.gitmodules index 4f3fb766..949580c7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "Source/Vendors/json"] path = Source/Vendors/json url = git@github.com:nlohmann/json.git -[submodule "Source/Vendors/dtl"] - path = Source/Vendors/dtl - url = git@github.com:cubicdaiya/dtl.git diff --git a/Source/Program/CommandController.cpp b/Source/Program/CommandController.cpp index 9d801b47..c6824743 100644 --- a/Source/Program/CommandController.cpp +++ b/Source/Program/CommandController.cpp @@ -96,7 +96,7 @@ void start_extension_server() { inline void print_default_help_info() { auto w = new TextWriter(); w->add_tab(2); - w->add_tab(12); + w->add_tab(10); w->write_line("Usage: l10ns [] "); w->newline(); w->write_line("Commands:"); @@ -188,7 +188,6 @@ int init(int argc, char* argv[]) { print_diagnostics(command->diagnostics); return 1; } - cout << command->diagnostics.size() << endl; if (command->is_requesting_version) { println("L10ns version ", VERSION, "."); } diff --git a/Source/Program/CommandParser.cpp b/Source/Program/CommandParser.cpp index 1ebfb157..4e858068 100644 --- a/Source/Program/CommandParser.cpp +++ b/Source/Program/CommandParser.cpp @@ -109,7 +109,6 @@ void set_command_flag(Command* command, const Flag* flag, char* value = NULL) { default: throw invalid_argument("Unknwon command flag."); } - } Command* parse_command_args(int argc, char* argv[]) { diff --git a/Source/Program/Diagnostics.cpp b/Source/Program/Diagnostics.cpp index 2bc231fe..d873743c 100644 --- a/Source/Program/Diagnostics.cpp +++ b/Source/Program/Diagnostics.cpp @@ -1,5 +1,6 @@ +// This code is auto generate. Don't edit! #include "Types.cpp" using namespace std; namespace D { - auto Do_someh_tig = new Diagnostic("Do someh '' tig"); + auto Do_someh_tig = new Diagnostic("Do someh tig"); } \ No newline at end of file diff --git a/Source/Program/Utils.cpp b/Source/Program/Utils.cpp index 1c977879..543b6c8d 100644 --- a/Source/Program/Utils.cpp +++ b/Source/Program/Utils.cpp @@ -19,6 +19,7 @@ using namespace std; using boost::asio::ip::tcp; +namespace fs = boost::filesystem; namespace L10ns { @@ -66,13 +67,14 @@ class TextWriter { } void tab() { - for (int i_tab = 0; i_tab < tabs.size(); i_tab++) { - if (column < this->tabs[i_tab]) { + for (int i_tab = 0; i_tab < this->tabs.size(); i_tab++) { + if (this->column < this->tabs[i_tab]) { int diff = this->tabs[i_tab] - column; - for (int i_diff = 0; i_diff < i_tab; i_diff++) { + for (int i_diff = 0; i_diff < diff; i_diff++) { this->text += " "; } this->column += diff; + break; } } } @@ -100,8 +102,8 @@ class TextWriter { this->column += text.size(); } - void write_line(string p_text) { - this->text += p_text; + void write_line(string text) { + this->write(text); this->newline(); } @@ -170,28 +172,26 @@ inline void write_file(string filename, string content) { f.close(); } -void remove(string p_path) { - boost::filesystem::path path(p_path); - boost::filesystem::remove_all(path); +void remove_all(string path) { + fs::remove_all(fs::path(path)); } -bool copy_folder(boost::filesystem::path const & source, boost::filesystem::path const & destination) { - namespace fs = boost::filesystem; +bool copy_folder(fs::path const & source, fs::path const & destination) { try { if (!fs::exists(source) || !fs::is_directory(source)) { - std::cerr << "Source directory " << source.string() - << " does not exist or is not a directory." << '\n' + std::cerr << "Source directory '" << source.string() + << "' does not exist or is not a directory." << '\n' ; return false; } if (fs::exists(destination)) { - std::cerr << "Destination directory " << destination.string() - << " already exists." << '\n'; + std::cerr << "Destination directory '" << destination.string() + << "' already exists." << '\n'; return false; } if (!fs::create_directory(destination)) { - std::cerr << "Unable to create destination directory" << destination.string() << '\n'; + std::cerr << "Unable to create destination directory '" << destination.string() << "'.\n"; return false; } } diff --git a/Source/TestFramework/Core.cpp b/Source/TestFramework/Core.cpp index d8fd5ab8..6487aff8 100644 --- a/Source/TestFramework/Core.cpp +++ b/Source/TestFramework/Core.cpp @@ -9,26 +9,29 @@ using namespace std; using namespace L10ns; +typedef char elem; +typedef std::string sequence; + namespace TestFramework { struct Test { string name; - function procedure; + function procedure; bool success; - Test(string name, function procedure): name(name), procedure(procedure) { + Test(string name, function procedure): name(name), procedure(procedure) { } }; struct Domain { string name; - vectortests = {}; + vectortests = {}; Domain(string name): name(name) { } }; -vector domains = {}; +vector domains = {}; Domain * currentDomain; void domain(string name) { @@ -36,7 +39,7 @@ void domain(string name) { domains.push_back(currentDomain); } -void test(string name, function procedure) { +void test(string name, function procedure) { auto test = new Test(name, procedure); currentDomain->tests.push_back(test); } @@ -59,17 +62,19 @@ int printResult() { } } - cout << "\e[32m " + to_string(testsSucceded) + " passed\e[0m" << endl; - cout << "\e[31m " + to_string(testsFailed) + " failed\e[0m" << endl; - cout << " " + to_string(testsSucceded + testsFailed) + " total" << endl; + cout << "\e[32m " + to_string(testsSucceded) + " passed\e[0m" << endl; + cout << "\e[31m " + to_string(testsFailed) + " failed\e[0m" << endl; + cout << " " + to_string(testsSucceded + testsFailed) + " total" << endl; int domainSize = domains.size(); string domain = domainSize == 1 ? " domain" : " domains"; - cout << " " + to_string(domainSize) + domain << endl; + cout << " " + to_string(domainSize) + domain << endl; if (testsFailed > 0) { + cout << endl; + cout << "Failed tests:" << endl; cout << endl; for (auto const & t : failedTests) { - cout << "\e[31m " + t->name + "\e[0m" << endl; + cout << "\e[31m " + t->name + "\e[0m" << endl; } } @@ -79,11 +84,11 @@ int printResult() { void runTests() { cout << endl; for (auto const & d : domains) { - cout << " " + d->name + ":" << endl; - cout << " "; + cout << d->name + ":" << endl; + cout << " "; for (auto const & t : d->tests) { try { - t->procedure(); + t->procedure(t); cout << "\e[32m․\e[0m"; t->success = true; } diff --git a/Source/TestFramework/ProjectTestRunner.cpp b/Source/TestFramework/ProjectTestRunner.cpp index 118418fc..38d9e70e 100644 --- a/Source/TestFramework/ProjectTestRunner.cpp +++ b/Source/TestFramework/ProjectTestRunner.cpp @@ -23,7 +23,7 @@ void addProjectTests() { recursively_create_folder(current_folder); write_file(current_folder + "/stdout.out", result); string test_name = p.substr(p.find_last_of("/") + 1); - test(test_name, [result, p]() { + test(test_name, [result, p](Test* t) { string reference_file = replace_string(p, "/Cases/", "/Reference/"); string reference = read_file(reference_file + "/stdout.out"); if (result != reference) { diff --git a/Source/Vendors/dtl b/Source/Vendors/dtl deleted file mode 160000 index 33a68d8c..00000000 --- a/Source/Vendors/dtl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 33a68d8c2dfbcbb0736af50301342ad082cdaefb diff --git a/Tasks/AcceptBaseline.cpp b/Tasks/AcceptBaseline.cpp index 17ff3f1e..f66ad604 100644 --- a/Tasks/AcceptBaseline.cpp +++ b/Tasks/AcceptBaseline.cpp @@ -5,6 +5,6 @@ using namespace L10ns; int main() { - remove(PROJECT_DIR "Tests/Reference"); + remove_all(PROJECT_DIR "Tests/Reference"); copy_folder(PROJECT_DIR "Tests/Current", PROJECT_DIR "Tests/Reference"); } diff --git a/Tasks/GenerateDiagnostics.cpp b/Tasks/GenerateDiagnostics.cpp index daf24a30..ea78f211 100644 --- a/Tasks/GenerateDiagnostics.cpp +++ b/Tasks/GenerateDiagnostics.cpp @@ -12,6 +12,8 @@ using namespace L10ns; using json = nlohmann::json; string output = + "// This code is auto generate. Don't edit!" + "\n" "#include \"Types.cpp\"" "\n" "using namespace std;" diff --git a/Tests/Reference/Projects/DefaultHelp/stdout.out b/Tests/Reference/Projects/DefaultHelp/stdout.out index 4b0b15b2..49c0bc6e 100644 --- a/Tests/Reference/Projects/DefaultHelp/stdout.out +++ b/Tests/Reference/Projects/DefaultHelp/stdout.out @@ -2,14 +2,14 @@ Usage: l10ns [] Commands: - init Initialize project. - sync Synchronize localization keys. - log Show latest added localizations. - set Set localization. + init Initialize project. + sync Synchronize localization keys. + log Show latest added localizations. + set Set localization. For more details: 'l10ns --help'. Options: - --help, -h Print help description. - --version Print current version. + --help, -h Print help description. + --version Print current version. diff --git a/Tests/Reference/Projects/UnknownCommandOption/stdout.out b/Tests/Reference/Projects/UnknownCommandOption/stdout.out new file mode 100644 index 00000000..2ece9218 --- /dev/null +++ b/Tests/Reference/Projects/UnknownCommandOption/stdout.out @@ -0,0 +1 @@ +Do someh tig