Files
clice/tests/unit/unit_tests.cc
ykiko cc5b25d5c3 refactor: public feature types and snapshot testing infrastructure (#442)
## Summary

- **Public feature types**: Move `SemanticToken`, `FoldingRange`,
`DocumentSymbol`, `InlayHint`, and `HintCategory` from internal `.cpp`
files to `feature.h` as public API types. Each feature now exposes two
overloads: a raw overload returning offset-based types and a protocol
overload that converts to LSP wire-format with explicit
`PositionEncoding`.
- **Snapshot testing**: Add corpus-driven snapshot tests using
`ASSERT_SNAPSHOT_GLOB` for semantic tokens, folding ranges, inlay hints,
document symbols, and TU index. Tests compile real C++ corpus files,
format output as YAML flow mappings, and diff against `.snap.yml`
baselines.
- **Test infrastructure**: Add `compile_file()` to `Tester`,
`yaml_str()` utility, `--corpus-dir` / `--snapshot-dir` CLI options, and
`--verbose` flag for unit tests. Migrate to kotatsu's unified
`kota::zest::Options` API.
- **Toolchain robustness**: Filter unknown cc1 args via
`clang::driver::getDriverOptTable()` to handle system compilers newer
than embedded LLVM.
- **Dependency bump**: Update kotatsu to 7381404 (unified zest Options,
out-param `from_json` API).

## Details

### Feature type changes
All five feature modules (`semantic_tokens`, `folding_ranges`,
`document_symbols`, `inlay_hints`, `document_links`) now follow the same
two-overload pattern. The raw overload returns offset-based structs
suitable for indexing and testing; the protocol overload adds
`PositionEncoding` conversion for LSP responses. `stateful_worker.cpp`
explicitly passes `PositionEncoding::UTF16` at every call site.

### Snapshot tests
Corpus files live in `tests/corpus/` (organized by language construct).
Snapshot baselines live in `tests/snapshots/<feature>/`. Format lambdas
are inlined directly in test bodies — no separate format functions for
single-use formatters. YAML output uses flow mappings (`- { key: value
}`) for compact, diffable baselines.

### cc1 arg filtering
`src/command/toolchain.cpp` now parses the cc1 argument list through
LLVM's driver option table and drops any args classified as
`UnknownClass`. This prevents compilation failures when the system
compiler emits flags that the embedded LLVM version doesn't recognize.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-24 19:36:27 +08:00

68 lines
1.9 KiB
C++

#include <string>
#include <string_view>
#include "test/platform.h"
#include "support/logging.h"
#include "kota/deco/deco.h"
#include "kota/zest/zest.h"
namespace {
using kota::deco::decl::KVStyle;
struct TestOptions {
kota::zest::Options zest;
DecoKVStyled(KVStyle::JoinedOrSeparate, help = "log level: trace/debug/info/warn/err";
required = false)
<std::string> log_level;
DecoKVStyled(KVStyle::JoinedOrSeparate, meta_var = "<DIR>"; help = "test data directory";
required = false)
<std::string> test_dir;
DecoKVStyled(KVStyle::JoinedOrSeparate, meta_var = "<DIR>";
help = "corpus directory for snapshot glob tests";
required = false)
<std::string> corpus_dir;
};
} // namespace
int main(int argc, const char** argv) {
auto args = kota::deco::util::argvify(argc, argv);
auto parsed = kota::deco::cli::parse<TestOptions>(args);
if(!parsed.has_value()) {
return 1;
}
auto& opts = parsed->options;
if(opts.test_dir.has_value())
clice::testing::test_dir = *opts.test_dir;
if(opts.corpus_dir.has_value())
clice::testing::corpus_dir = *opts.corpus_dir;
if(opts.log_level.has_value()) {
auto level = *opts.log_level;
if(level == "trace") {
clice::logging::options.level = clice::logging::Level::trace;
} else if(level == "debug") {
clice::logging::options.level = clice::logging::Level::debug;
} else if(level == "info") {
clice::logging::options.level = clice::logging::Level::info;
} else if(level == "warn") {
clice::logging::options.level = clice::logging::Level::warn;
} else if(level == "err") {
clice::logging::options.level = clice::logging::Level::err;
}
}
clice::logging::stderr_logger("test", clice::logging::options);
return kota::zest::run_tests(std::move(opts.zest));
}