Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/core/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ std::vector<std::string> getPracticeDockerArgs(RunPracticeParams const & params)
runArgs.emplace_back(cmd);
runArgs.emplace_back(script);

runArgs.emplace_back(fmt::format("-f {}", params.practice.project.name));

// TODO check -f parameter. It's absent for C++ practice. Do we need it?
// see run.sh for python pracitce
auto runAction = [&runArgs, &params]() {
runArgs.emplace_back(
fmt::format("-p practice/{}", params.pathToMainFile)); // TODO remove this properly
runArgs.emplace_back(fmt::format("-o {}", params.userCmdLineArgs));
if (!params.userCmdLineArgs.empty()) {
runArgs.emplace_back(fmt::format("-o {}", params.userCmdLineArgs));
}
runArgs.emplace_back(fmt::format("-r"));
};

auto testAction = [&runArgs, &params]() {
runArgs.emplace_back(fmt::format("-f {}", params.practice.project.name));
runArgs.emplace_back(fmt::format("-t"));
};
auto testAction = [&runArgs, &params]() { runArgs.emplace_back(fmt::format("-t")); };

switch (params.practice.action) {
case PracticeAction::Run: runAction(); break;
Expand Down
6 changes: 5 additions & 1 deletion tests/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
"python": {
"image-name": "senjun_python",
"launched": 1
},
"cpp": {
"image-name": "senjun_cpp",
"launched": 1
}
}
}
}
7 changes: 7 additions & 0 deletions tests/data/practice/cpp_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"project_contents": "{\"name\":\"project\",\"children\":[{\"name\":\"CMakeLists.txt\",\"contents\":\"cmake_minimum_required(VERSION 3.30.0 FATAL_ERROR)\\n\\n# Включаем флаг для возможности `import std`.\\n# Эта строка должна идти ДО объявления, что проект на C++ (значение CXX).\\nset(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD\\n \\\"0e5b6991-d74f-4b3d-a41c-cf096e0b2508\\\")\\n\\n# Для всех целей сборки устанавливаем возможность импорта std в 1.\\nset(CMAKE_CXX_MODULE_STD 1)\\n\\nSET(CMAKE_CXX_FLAGS \\\"${CMAKE_CXX_FLAGS} -stdlib=libc++ -Werror -Wall -O2\\\")\\n\\nproject(div_without_div LANGUAGES CXX)\\n\\nadd_executable(main)\\n\\ntarget_sources(main\\n PRIVATE\\n main.cpp)\\n\\ntarget_compile_features(main\\n PRIVATE cxx_std_23\\n INTERFACE cxx_std_23)\\n\\nadd_executable(tests)\\n\\ntarget_sources(tests\\nPRIVATE\\n tests.cpp)\\n\\ntarget_compile_features(tests\\nPRIVATE cxx_std_23\\nINTERFACE cxx_std_23)\\n\\n# Чтобы собрать проект локально, выполните:\\n# mkdir build \u0026\u0026 cd build\\n# cmake -Wno-dev -GNinja ..\\n# ninja\\n\",\"id\":2},{\"name\":\"div.h\",\"contents\":\"#pragma once\\n\\ninline int divide(int a, int b) {\\n // Ваше решение\\nreturn 0;}\\n\",\"id\":3},{\"name\":\"main.cpp\",\"contents\":\"#include \\\"div.h\\\"\\n\\n#include \u003cprint\u003e\\n\\nint main() {\\n std::println(\\\"{}\\\", divide(11, 5)); // 2\\n std::println(\\\"{}\\\", divide(5, 11)); // 0\\n}\",\"is_main_file\":true,\"id\":4},{\"name\":\"tests.cpp\",\"contents\":\"#include \\\"ut.hpp\\\" // Библиотка для юнит-тестов\\n\\n#include \\\"div.h\\\"\\n\\n// Юнит-тесты\\nint main() {\\n using namespace boost::ut;\\n\\n \\\"Simple cases\\\"_test = [] {\\n expect(divide(1, 1) == 1);\\n expect(divide(1, 2) == 0);\\n expect(divide(2, 1) == 2);\\n expect(divide(3, 2) == 1);\\n expect(divide(10, 2) == 5);\\n expect(divide(11, 2) == 5);\\n };\\n}\",\"id\":5}],\"id\":1}",
"project_id": "cpp_div_without_div",
"course_id": "cpp",
"user_cmd_line_args": "",
"action": "run"
}
7 changes: 7 additions & 0 deletions tests/data/practice/cpp_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"project_contents": "{\"name\":\"project\",\"children\":[{\"name\":\"CMakeLists.txt\",\"contents\":\"cmake_minimum_required(VERSION 3.30.0 FATAL_ERROR)\\n\\n# Включаем флаг для возможности `import std`.\\n# Эта строка должна идти ДО объявления, что проект на C++ (значение CXX).\\nset(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD\\n \\\"0e5b6991-d74f-4b3d-a41c-cf096e0b2508\\\")\\n\\n# Для всех целей сборки устанавливаем возможность импорта std в 1.\\nset(CMAKE_CXX_MODULE_STD 1)\\n\\nSET(CMAKE_CXX_FLAGS \\\"${CMAKE_CXX_FLAGS} -stdlib=libc++ -Werror -Wall -O2\\\")\\n\\nproject(div_without_div LANGUAGES CXX)\\n\\nadd_executable(main)\\n\\ntarget_sources(main\\n PRIVATE\\n main.cpp)\\n\\ntarget_compile_features(main\\n PRIVATE cxx_std_23\\n INTERFACE cxx_std_23)\\n\\nadd_executable(tests)\\n\\ntarget_sources(tests\\nPRIVATE\\n tests.cpp)\\n\\ntarget_compile_features(tests\\nPRIVATE cxx_std_23\\nINTERFACE cxx_std_23)\\n\\n# Чтобы собрать проект локально, выполните:\\n# mkdir build \u0026\u0026 cd build\\n# cmake -Wno-dev -GNinja ..\\n# ninja\\n\",\"id\":2},{\"name\":\"div.h\",\"contents\":\"#pragma once\\n\\ninline int divide(int a, int b) {\\n while(true);// Ваше решение\\nreturn 0;}\\n\",\"id\":3},{\"name\":\"main.cpp\",\"contents\":\"#include \\\"div.h\\\"\\n\\n#include \u003cprint\u003e\\n\\nint main() {\\n std::println(\\\"{}\\\", divide(11, 5)); // 2\\n std::println(\\\"{}\\\", divide(5, 11)); // 0\\n}\",\"is_main_file\":true,\"id\":4},{\"name\":\"tests.cpp\",\"contents\":\"#include \\\"ut.hpp\\\" // Библиотка для юнит-тестов\\n\\n#include \\\"div.h\\\"\\n\\n// Юнит-тесты\\nint main() {\\n using namespace boost::ut;\\n\\n \\\"Simple cases\\\"_test = [] {\\n expect(divide(1, 1) == 1);\\n expect(divide(1, 2) == 0);\\n expect(divide(2, 1) == 2);\\n expect(divide(3, 2) == 1);\\n expect(divide(10, 2) == 5);\\n expect(divide(11, 2) == 5);\\n };\\n}\",\"id\":5}],\"id\":1}",
"project_id": "cpp_div_without_div",
"course_id": "cpp",
"user_cmd_line_args": "",
"action": "test"
}
3 changes: 3 additions & 0 deletions tests/service/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ std::string const kHaskellProject = "haskell_playground.json";

std::string const kPythonPracticeRun = "practice/python_run.json";
std::string const kPythonPracticeTest = "practice/python_test.json";

std::string const kCppPracticeRun = "practice/cpp_run.json";
std::string const kCppPracticeTest = "practice/cpp_test.json";
2 changes: 1 addition & 1 deletion tests/service/courses_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ TEST(Courses, Rust) {
std::string testingCode =
"/* You can edit and run this code. */\n\nfn main() {\n println!(\"Hello world!\");\n}\n";
watchman::ChapterTaskParams const params{
{watchman::Language::RUST}, std::move(sourceCode), std::move(testingCode)};
{watchman::Language::RUST, {}}, std::move(sourceCode), std::move(testingCode)};
watchman::Response response = service.runChapter(params);
ASSERT_EQ(response.sourceCode, 0);
ASSERT_EQ(response.output, "Hello world!\r\n");
Expand Down
14 changes: 13 additions & 1 deletion tests/service/practice_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@

TEST(Practice, RunTest) {
watchman::Service service(watchman::readConfig(kParams.config));
watchman::RunPracticeParams params = watchman::parsePractice(getFileContent(kPythonPracticeRun));
watchman::RunPracticeParams params =
watchman::parsePractice(getFileContent(kPythonPracticeRun));
auto response = service.runPractice(params);
ASSERT_TRUE(response.sourceCode == watchman::kSuccessCode);

params = watchman::parsePractice(getFileContent((kPythonPracticeTest)));
response = service.runPractice(params);
ASSERT_TRUE(response.sourceCode == watchman::kTestsError);
}

TEST(Practice, RunCpp) {
watchman::Service service(watchman::readConfig(kParams.config));
watchman::RunPracticeParams params = watchman::parsePractice(getFileContent(kCppPracticeRun));
auto response = service.runPractice(params);
ASSERT_TRUE(response.sourceCode == watchman::kSuccessCode);

params = watchman::parsePractice(getFileContent((kCppPracticeTest)));
response = service.runPractice(params);
ASSERT_TRUE(response.sourceCode == watchman::kTestsError);
}