Complete build wiring and CLI file commands
Align documented commands with the CLI, enable optional GUI/test targets, and remove committed API secrets so the project is safer to build and run. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,18 @@
|
||||
# tests — 单元测试
|
||||
# ============================================================
|
||||
|
||||
# TODO: 引入测试框架后启用
|
||||
# enable_testing()
|
||||
# add_subdirectory(...)
|
||||
add_executable(dstalk-smoke-test
|
||||
smoke_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(dstalk-smoke-test
|
||||
PRIVATE dstalk
|
||||
)
|
||||
|
||||
add_custom_command(TARGET dstalk-smoke-test POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_FILE:dstalk>
|
||||
$<TARGET_FILE_DIR:dstalk-smoke-test>
|
||||
)
|
||||
|
||||
add_test(NAME dstalk-smoke-test COMMAND dstalk-smoke-test)
|
||||
|
||||
52
tests/smoke_test.cpp
Normal file
52
tests/smoke_test.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "dstalk/dstalk_api.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto dir = std::filesystem::temp_directory_path() / "dstalk-smoke-test";
|
||||
std::filesystem::create_directories(dir);
|
||||
|
||||
const auto config_path = dir / "config.toml";
|
||||
{
|
||||
std::ofstream config(config_path);
|
||||
config << "[api]\n"
|
||||
<< "provider = \"deepseek\"\n"
|
||||
<< "base_url = \"https://api.deepseek.com/v1\"\n"
|
||||
<< "api_key = \"test-key\"\n"
|
||||
<< "model = \"deepseek-chat\"\n";
|
||||
}
|
||||
|
||||
if (dstalk_init(config_path.string().c_str()) != 0) {
|
||||
std::cerr << "dstalk_init failed\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const auto file_path = dir / "sample.txt";
|
||||
if (dstalk_file_write(file_path.string().c_str(), "hello dstalk") != 0) {
|
||||
std::cerr << "dstalk_file_write failed\n";
|
||||
dstalk_destroy();
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* content = nullptr;
|
||||
if (dstalk_file_read(file_path.string().c_str(), &content) != 0 || !content) {
|
||||
std::cerr << "dstalk_file_read failed\n";
|
||||
dstalk_destroy();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const bool ok = std::strcmp(content, "hello dstalk") == 0;
|
||||
dstalk_free_string(content);
|
||||
dstalk_destroy();
|
||||
|
||||
if (!ok) {
|
||||
std::cerr << "unexpected file content\n";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user