Files
fn_registry/cpp/apps/text_editor_smoke/main.cpp
T
egutierrez 61a238b3fd test(cpp): add text_editor_smoke build gate for issue 0025
App minima (no abre ventana ImGui) que crea/settea/lee text_editor y registra
un watch sobre /tmp/fn_smoke_test.txt para confirmar que TextEditor.cpp del
vendor + text_editor.cpp + file_watcher.cpp enlazan correctamente. Activada
por defecto si la carpeta existe (no requiere la primitives_gallery).

Tambien anade flag FN_BUILD_GALLERY (OFF default) para no romper el build
cuando la primitives_gallery no esta presente — sus deps (button.cpp,
toolbar.cpp...) son sources untracked en algunas branches.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 21:00:47 +02:00

65 lines
2.1 KiB
C++

// Smoke test (no GUI): compila y ejecuta brevemente las APIs nuevas del
// issue 0025 para validar que el wrapper PIMPL del text_editor y el
// file_watcher (inotify Linux / ReadDirectoryChangesW Win) enlazan.
//
// No abre ventana ImGui — solo crea / settea texto / lee / poll / destruye.
#include "core/text_editor.h"
#include "core/file_watcher.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <thread>
#include <chrono>
int main() {
// ----- text_editor -----
auto* ed = fn::text_editor_create(fn::CodeLang::GLSL);
if (!ed) { std::fprintf(stderr, "text_editor_create returned null\n"); return 1; }
fn::text_editor_set_text(ed, "void main(){}\n");
const char* got = fn::text_editor_get_text(ed);
std::printf("text_editor: get_text -> %zu bytes\n", got ? std::strlen(got) : 0u);
if (fn::text_editor_is_dirty(ed)) {
std::fprintf(stderr, "text_editor: dirty unexpected after set_text\n");
return 1;
}
fn::text_editor_destroy(ed);
// ----- file_watcher -----
const char* path = "/tmp/fn_smoke_test.txt";
std::remove(path);
{
FILE* f = std::fopen(path, "w"); std::fputs("init\n", f); std::fclose(f);
}
auto* fw = fn::file_watcher_create();
if (!fw) { std::fprintf(stderr, "file_watcher_create returned null\n"); return 1; }
if (!fn::file_watcher_add(fw, path)) {
std::fprintf(stderr, "file_watcher_add failed: %s\n", fn::file_watcher_last_error(fw));
// Aun asi continuamos: en CI sin inotify (raro) este test seria flaky.
}
// Modificar
{
FILE* f = std::fopen(path, "w"); std::fputs("changed\n", f); std::fclose(f);
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
auto evs = fn::file_watcher_poll(fw);
std::printf("file_watcher: %zu events\n", evs.size());
for (auto& e : evs) {
const char* kind = e.kind == fn::FileEvent::Modified ? "MOD"
: e.kind == fn::FileEvent::Created ? "NEW" : "DEL";
std::printf(" [%s] %s\n", kind, e.path.c_str());
}
fn::file_watcher_destroy(fw);
std::remove(path);
std::printf("OK\n");
return 0;
}