diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index cd837ff..29322dc 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -1,13 +1,13 @@ -name: "Lint" -description: "Lint Python code" +name: 'Lint' +description: 'Lint Python code' runs: - using: "composite" + using: 'composite' steps: - name: Install Python uses: actions/setup-python@v2 with: - python-version: "3.x" + python-version: '3.x' - name: Pip cache uses: actions/cache@v2 @@ -43,3 +43,12 @@ runs: uses: actions-rust-lang/rustfmt@v1 with: manifest-path: packages/rust/lsprotocol/Cargo.toml + + - name: Dotnet Tool Chain setup + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '6.0.x' + + - name: Dotnet Format Check + run: dotnet format packages/dotnet/lsprotocol/lsprotocol.csproj --verify-no-changes + shell: bash diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 99a8fb7..547fcaa 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -24,8 +24,8 @@ jobs: - name: Lint uses: ./.github/actions/lint - tests: - name: Tests + python-tests: + name: Python Tests runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -50,6 +50,42 @@ jobs: run: python -m nox --session tests shell: bash + dotnet-tests: + name: Dotnet Tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Dotnet Tool Chain setup + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '6.0.x' + + - name: Install Generator + run: python -m pip install -r ./requirements.txt + + - name: Generate Test Data + run: python -m generator --plugin testdata + + - name: Generate C# Code + run: python -m generator --plugin dotnet + + - name: Dotnet Run Tests + run: dotnet test tests/dotnet/lsprotocol_tests/lsprotocol_tests.csproj + shell: bash + env: + LSP_TEST_DATA_PATH: ${{ github.workspace }}/packages/testdata + smoke-tests: name: Smoke Tests (pygls) runs-on: ${{ matrix.os }} diff --git a/.github/workflows/push-check.yml b/.github/workflows/push-check.yml index 18cb604..61b59d9 100644 --- a/.github/workflows/push-check.yml +++ b/.github/workflows/push-check.yml @@ -3,10 +3,10 @@ name: Push Validation on: push: branches: - - "main" - - "release" - - "release/*" - - "release-*" + - 'main' + - 'release' + - 'release/*' + - 'release-*' jobs: build-vsix: @@ -29,24 +29,24 @@ jobs: - name: Lint uses: ./.github/actions/lint - tests: - name: Tests + python-tests: + name: Python Tests runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - python: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python: ['3.7', '3.8', '3.9', '3.10', '3.11'] steps: - name: Checkout uses: actions/checkout@v3 - - name: Update pip, install wheel and nox - run: python -m pip install -U pip wheel nox - shell: bash + - name: Use Python ${{ matrix.python }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} - # The new python may not have nox so install it again - name: Update pip, install wheel and nox run: python -m pip install -U pip wheel nox shell: bash @@ -54,3 +54,39 @@ jobs: - name: Run tests run: python -m nox --session tests shell: bash + + dotnet-tests: + name: Dotnet Tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Dotnet Tool Chain setup + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '6.0.x' + + - name: Install Generator + run: python -m pip install -r ./requirements.txt + + - name: Generate Test Data + run: python -m generator --plugin testdata + + - name: Generate C# Code + run: python -m generator --plugin dotnet + + - name: Dotnet Run Tests + run: dotnet test tests/dotnet/lsprotocol_tests/lsprotocol_tests.csproj + shell: bash + env: + LSP_TEST_DATA_PATH: ${{ github.workspace }}/packages/testdata diff --git a/generator/plugins/testdata/testdata_utils.py b/generator/plugins/testdata/testdata_utils.py index a0d60fa..879ce2f 100644 --- a/generator/plugins/testdata/testdata_utils.py +++ b/generator/plugins/testdata/testdata_utils.py @@ -14,8 +14,12 @@ def generate_from_spec(spec: model.LSPModel, output_dir: str) -> None: """Generate the code for the given spec.""" - cleanup(output_dir) output = pathlib.Path(output_dir) + + if not output.exists(): + output.mkdir(parents=True, exist_ok=True) + + cleanup(output) # key is the relative path to the file, value is the content code: Dict[str, str] = generate(spec, logger) for file_name in code: @@ -24,8 +28,7 @@ def generate_from_spec(spec: model.LSPModel, output_dir: str) -> None: file.write_text(code[file_name], encoding="utf-8") -def cleanup(output_dir: str) -> None: +def cleanup(output_path: pathlib.Path) -> None: """Cleanup the generated C# files.""" - output = pathlib.Path(output_dir) - for file in output.glob("*.json"): + for file in output_path.glob("*.json"): file.unlink() diff --git a/tests/dotnet/lsprotocol_tests/LSPTests.cs b/tests/dotnet/lsprotocol_tests/LSPTests.cs index 132f923..4d71450 100644 --- a/tests/dotnet/lsprotocol_tests/LSPTests.cs +++ b/tests/dotnet/lsprotocol_tests/LSPTests.cs @@ -61,7 +61,7 @@ private static void RunTest(bool valid, string data, Type type) JToken token2 = JToken.Parse(newJson); RemoveNullProperties(token1); RemoveNullProperties(token2); - Assert.True(JToken.DeepEquals(token1, token2)); + Assert.True(JToken.DeepEquals(token1, token2), $"Failed for : {data}"); } else { @@ -69,7 +69,7 @@ private static void RunTest(bool valid, string data, Type type) { JsonConvert.DeserializeObject(data, type); // Explicitly fail the test - Assert.True(false, "Should have thrown an exception."); + Assert.True(false, $"Should have thrown an exception for : {data}"); } catch {