mirror of
https://github.com/microsoft/WSL.git
synced 2026-04-12 04:55:36 -05:00
* docs: overhaul Copilot instructions with coding conventions and prompt files Major update to .github/copilot-instructions.md: - Add coding conventions (naming, error handling, RAII, strings, headers, synchronization, localization, telemetry, formatting, IDL/COM, config) - Add test authoring summary pointing to detailed test.md prompt - Add namespace-to-directory map for top-level namespaces - Add key source files list (defs.h, WslTelemetry.h, wslc.idl, etc.) - Replace clang-format references with .\FormatSource.ps1 - Consolidate duplicate timing info into single reference table New files: - .github/copilot/review.md: Review prompt focused on high-risk areas (ABI breaks, missing localization, resource safety) - .github/copilot/test.md: Test generation prompt with TAEF patterns - .github/copilot/commit.md: Commit message guidelines - .editorconfig: Editor settings for non-C++ files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs: address PR review feedback - Scope precomp.h guidance to Windows components (Linux doesn't use it) - Fix review.md reference to .github/copilot-instructions.md - Restore clang-format as Linux formatting option alongside FormatSource.ps1 - Note FormatSource.ps1 requires cmake . first - Fix en-us -> en-US casing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2.8 KiB
2.8 KiB
Test Generation Guidelines for WSL
When generating tests for this repository, follow these patterns:
Framework
Tests use TAEF (Test Authoring and Execution Framework). Always include "Common.h".
Test Class Structure
#include "Common.h"
namespace MyFeatureTests
{
class MyFeatureTests
{
WSL_TEST_CLASS(MyFeatureTests)
TEST_CLASS_SETUP(TestClassSetup)
{
VERIFY_ARE_EQUAL(LxsstuInitialize(FALSE), TRUE);
return true;
}
TEST_CLASS_CLEANUP(TestClassCleanup)
{
LxsstuUninitialize(FALSE);
return true;
}
TEST_METHOD(DescriptiveTestName)
{
// Test implementation
}
};
}
Key Rules
- Use
WSL_TEST_CLASS(Name)— never rawBEGIN_TEST_CLASS - Setup/cleanup methods must
return trueon success - Use
VERIFY_*macros for assertions — neverassert()or exceptions for test validation
Assertion Macros
VERIFY_ARE_EQUAL(expected, actual)— value equalityVERIFY_ARE_NOT_EQUAL(a, b)— value inequalityVERIFY_IS_TRUE(condition)— boolean checkVERIFY_IS_FALSE(condition)— negative boolean checkVERIFY_IS_NULL(ptr)— null checkVERIFY_IS_NOT_NULL(ptr)— non-null checkVERIFY_WIN32_BOOL_SUCCEEDED(expr)— Win32 BOOL resultVERIFY_SUCCEEDED(hr)— HRESULT success
Logging in Tests
LogInfo(fmt, ...)— informational messagesLogError(fmt, ...)— error messagesLogWarning(fmt, ...)— warningsLogPass(fmt, ...)— explicit pass messagesLogSkipped(fmt, ...)— skip messages
Conditional Skipping
Add skip macros at the start of a test method body when the test only applies to certain environments:
TEST_METHOD(Wsl2SpecificTest)
{
WSL2_TEST_ONLY();
// ... test code ...
}
Available skip macros:
WSL1_TEST_ONLY()— skip unless WSL1WSL2_TEST_ONLY()— skip unless WSL2SKIP_TEST_ARM64()— skip on ARM64SKIP_TEST_UNSTABLE()— skip known-flaky testsWINDOWS_11_TEST_ONLY()— skip on pre-Windows 11WSL_TEST_VERSION_REQUIRED(version)— skip if WSL version too old
RAII Test Helpers
WslKeepAlive— prevents UVM timeout during long-running tests; create at test startWslConfigChange— RAII wrapper that applies a temporary.wslconfigand restores the original on destruction:
TEST_METHOD(TestWithCustomConfig)
{
WslConfigChange config(L"[wsl2]\nmemory=4GB\n");
// ... test with custom config ...
// Original .wslconfig restored when config goes out of scope
}
Memory in Tests
- Use
ALLOC(size)/FREE(ptr)macros for direct heap allocation in tests - Prefer RAII wrappers and smart pointers for production-like code paths
Test Naming
- Use descriptive PascalCase names that describe the scenario:
CreateInstanceWithInvalidGuidFails,EchoTest,MountPlan9Share - Group related tests in the same test class