Skip to content

Commit 68454e3

Browse files
authored
🐛 QD-11464: clang subproject's tests do not work (#568)
* 🐛 QD-11464: Fix tests for clang not running on GitHub * 🐛 QD-11464: Fix failing test * 🐛 QD-11464: Revert "Fix tests for clang not running on GitHub" This reverts commit 91a7143. * Fix .NET tests * 🐛 QD-11464: Minor fixes * 🐛 QD-11464: Fix TestDirLanguagesExcluded being dependent on languages in repo * 🐛 QD-11464: Fix unused import * 🐛 QD-11464: Perform an explicit build in CI to avoid panics on test * 🐛 QD-11464: Fix recognizeDirLanguages not excluding folders with backslashes * ♻️ QD-11464: Use the same shell on all machines in CI * 🐛 QD-11464: Do not rely on tar's BSD extension for opening zip files * 🐛 Add linter field to cdnet test project * 🐛 QD-11464: Add back forgotten commandline switch * ♻️ QD-11464: Use built-in functionality for temp test dirs * ♻️ QD-11464: Use up-to-date .net in test project * 🐛 QD-11464: Fix recognizeDirLanguages being randomly ordered * ⏪ QD-11464: Revert improvements to zip extracting * 🐛 QD-11464: Linter choice is not fixed when launching a third-party linter * 🧱 Update qodana-clang prodcut code * ♻️ Use product code for running third-party linters * 🔊 Change wording in warning message * ⏪ QD-11464: Revert previous formatting changes * ✅ QD-11464 Add more languages to TestDirLanguagesExcluded
1 parent 38a6b1f commit 68454e3

File tree

29 files changed

+166
-177
lines changed

29 files changed

+166
-177
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ jobs:
5858
if: ${{ matrix.os != 'windows-latest' }}
5959
run: |
6060
set -euo pipefail
61-
go test -json -v $(go list -f '{{.Dir}}/...' -m | xargs) -coverprofile coverage-${{ matrix.os }}.out 2>&1 | tee /tmp/gotest.log | gotestfmt
61+
go test -json -v $(go list -f '{{.Dir}}/...' -m) -coverprofile coverage-${{ matrix.os }}.out 2>&1 | tee /tmp/gotest.log | gotestfmt
6262
env:
6363
QODANA_LICENSE_ONLY_TOKEN: ${{ secrets.QODANA_LICENSE_ONLY_TOKEN }}
6464
- name: Run tests (with coverage) for Windows
6565
if: ${{ matrix.os == 'windows-latest' }}
66-
run: go test -v $(go list -f '{{.Dir}}/...' -m | ForEach-Object { $_ }) -coverprofile coverage-${{ matrix.os }}.out
66+
run: go test -v $(go list -f '{{.Dir}}/...' -m) -coverprofile coverage-${{ matrix.os }}.out
6767
env:
6868
QODANA_LICENSE_ONLY_TOKEN: ${{ secrets.QODANA_LICENSE_ONLY_TOKEN }}
6969

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ go build -o qd main.go
3434

3535
Test your code with coverage:
3636
```sh
37-
go test -v $(go list -f '{{.Dir}}/...' -m | xargs)
37+
go test -v $(go list -f '{{.Dir}}/...' -m)
3838
```
3939

4040
Test your code with a human-readable report (requires `go install github.com/mfridman/tparse@latest`):
4141
```shell
4242
export GITHUB_ACTIONS=true # skip third-party linter tests
43-
set -o pipefail && go test -json -v $(go list -f '{{.Dir}}/...' -m | xargs) | tparse -all
43+
set -o pipefail && go test -json -v $(go list -f '{{.Dir}}/...' -m) | tparse -all
4444
```
4545

4646
Dry-run goreleaser:

cdnet/cdnet_test.go

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,44 @@ package main
1818

1919
import (
2020
"fmt"
21-
"github.com/JetBrains/qodana-cli/v2025/platform"
22-
"github.com/JetBrains/qodana-cli/v2025/platform/thirdpartyscan"
23-
log "github.com/sirupsen/logrus"
2421
"os"
25-
"os/exec"
2622
"path/filepath"
2723
"strings"
2824
"testing"
25+
26+
"github.com/JetBrains/qodana-cli/v2025/platform/thirdpartyscan"
27+
28+
"github.com/JetBrains/qodana-cli/v2025/platform"
29+
log "github.com/sirupsen/logrus"
2930
)
3031

3132
func TestLinterRun(t *testing.T) {
3233
// skip test on GH, since required jars are not there
3334
if os.Getenv("GITHUB_ACTIONS") == "true" {
3435
t.Skip()
3536
}
36-
projectPath := createNativeProject(t, "badrules")
37-
defer deferredCleanup(projectPath)
38-
outputDir := filepath.Join(os.TempDir(), "cdnet-output")
39-
defer deferredCleanup(outputDir)
40-
cacheDir := filepath.Join(os.TempDir(), "cdnetTmp")
41-
defer deferredCleanup(cacheDir)
37+
log.SetLevel(log.DebugLevel)
38+
39+
projectDir := t.TempDir()
40+
41+
err := os.CopyFS(projectDir, os.DirFS("testdata/TestLinterRun"))
42+
if err != nil {
43+
t.Fatal(err)
44+
}
45+
46+
outputDir := filepath.Join(projectDir, ".linter-output")
47+
cacheDir := filepath.Join(projectDir, ".linter-cache")
4248

4349
linterInfo := thirdpartyscan.LinterInfo{
4450
ProductCode: productCode,
4551
LinterName: linterName,
46-
LinterVersion: "2023.3",
52+
LinterVersion: version,
4753
IsEap: true,
4854
}
4955

5056
command := platform.NewThirdPartyScanCommand(CdnetLinter{}, linterInfo)
51-
command.SetArgs([]string{"-i", projectPath, "-o", outputDir, "--cache-dir", cacheDir, "--no-build"})
52-
err := command.Execute()
57+
command.SetArgs([]string{"-i", projectDir, "-o", outputDir, "--cache-dir", cacheDir, "--no-build"})
58+
err = command.Execute()
5359
if err != nil {
5460
t.Fatal(err)
5561
}
@@ -70,7 +76,7 @@ func TestLinterRun(t *testing.T) {
7076
fmt.Println("Found issues: ", resultsSize)
7177
}
7278

73-
resultAllProblems, err := os.ReadFile(filepath.Join(outputDir, "report", "results", "result-allProblems.json"))
79+
resultAllProblems, err := os.ReadFile(filepath.Join(outputDir, "report", "result-allProblems.json"))
7480
if err != nil {
7581
t.Fatal("Error reading all problems file", err)
7682
}
@@ -80,38 +86,3 @@ func TestLinterRun(t *testing.T) {
8086
t.Fatal("All problems file is empty")
8187
}
8288
}
83-
84-
func deferredCleanup(path string) {
85-
err := os.RemoveAll(path)
86-
if err != nil {
87-
log.Fatal(err)
88-
}
89-
}
90-
91-
func createNativeProject(t *testing.T, name string) string {
92-
home, err := os.UserHomeDir()
93-
if err != nil {
94-
t.Fatal(err)
95-
}
96-
location := filepath.Join(home, ".qodana_scan_", name)
97-
err = gitClone("https://github.com/hybloid/BadRulesProject", location)
98-
if err != nil {
99-
t.Fatal(err)
100-
}
101-
return location
102-
}
103-
104-
func gitClone(repoURL, directory string) error {
105-
if _, err := os.Stat(directory); !os.IsNotExist(err) {
106-
err = os.RemoveAll(directory)
107-
if err != nil {
108-
return err
109-
}
110-
}
111-
cmd := exec.Command("git", "clone", repoURL, directory)
112-
err := cmd.Run()
113-
if err != nil {
114-
return err
115-
}
116-
return nil
117-
}

cdnet/options_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func TestGetArgsThirdPartyLinters(t *testing.T) {
389389
name: "(clang) compile commands",
390390
cb: corescan.ContextBuilder{
391391
ClangCompileCommands: "compile_commands.json",
392-
Linter: product.DockerImageMap[product.QDCL],
392+
Linter: product.DockerImageMap[product.QDCLC],
393393
},
394394
expected: []string{
395395
"--compile-commands", "compile_commands.json",
@@ -399,7 +399,7 @@ func TestGetArgsThirdPartyLinters(t *testing.T) {
399399
name: "(clang) clang args",
400400
cb: corescan.ContextBuilder{
401401
ClangArgs: "-I/usr/include",
402-
Linter: product.DockerImageMap[product.QDCL],
402+
Linter: product.DockerImageMap[product.QDCLC],
403403
},
404404
expected: []string{
405405
"--clang-args", "-I/usr/include",

cdnet/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func (l CdnetLinter) MountTools(path string) (map[string]string, error) {
7272

7373
if _, err := os.Stat(val["clt"]); err != nil {
7474
if os.IsNotExist(err) {
75-
path := platform.ProcessAuxiliaryTool(archive, moniker, path, Clt)
76-
if err := platform.Decompress(path, path); err != nil {
75+
archivePath := platform.ProcessAuxiliaryTool(archive, moniker, path, Clt)
76+
if err := platform.Decompress(archivePath, path); err != nil {
7777
return nil, fmt.Errorf("failed to decompress %s archive: %w", moniker, err)
7878
}
7979
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class Program
2+
{
3+
public static void Main(string[] args)
4+
{
5+
int x;
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<OutputType>Exe</OutputType>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: "1.0"
2+
profile:
3+
name: qodana.recommended
4+
dotnet:
5+
project: TestLinterRun.csproj

clang/clang_test.go

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package main
22

33
import (
44
"fmt"
5-
"github.com/JetBrains/qodana-cli/v2025/platform/thirdpartyscan"
65
"os"
7-
"os/exec"
86
"path/filepath"
97
"strings"
108
"testing"
119

10+
"github.com/JetBrains/qodana-cli/v2025/platform/thirdpartyscan"
11+
1212
"github.com/JetBrains/qodana-cli/v2025/platform"
1313
log "github.com/sirupsen/logrus"
1414
)
@@ -19,24 +19,27 @@ func TestLinterRun(t *testing.T) {
1919
t.Skip()
2020
}
2121
log.SetLevel(log.DebugLevel)
22-
projectPath := createNativeProject(t, "cpp-demo")
23-
defer deferredCleanup(projectPath)
24-
outputDir := filepath.Join(os.TempDir(), "clang-output")
25-
defer deferredCleanup(outputDir)
26-
cacheDir := filepath.Join(os.TempDir(), "clangTmp")
27-
defer deferredCleanup(cacheDir)
22+
23+
projectDir := t.TempDir()
24+
25+
err := os.CopyFS(projectDir, os.DirFS("testdata/TestLinterRun"))
26+
if err != nil {
27+
t.Fatal(err)
28+
}
29+
30+
outputDir := filepath.Join(projectDir, ".linter-output")
31+
cacheDir := filepath.Join(projectDir, ".linter-cache")
2832

2933
linterInfo := thirdpartyscan.LinterInfo{
3034
ProductCode: productCode,
3135
LinterName: linterName,
32-
LinterVersion: "2023.3",
36+
LinterVersion: version,
3337
IsEap: true,
3438
}
3539

3640
command := platform.NewThirdPartyScanCommand(ClangLinter{}, linterInfo)
37-
command.SetArgs([]string{"-i", projectPath, "-o", outputDir, "--cache-dir", cacheDir})
38-
err := command.Execute()
39-
defer deferredCleanup(cacheDir)
41+
command.SetArgs([]string{"-i", projectDir, "-o", outputDir, "--cache-dir", cacheDir})
42+
err = command.Execute()
4043
if err != nil {
4144
t.Fatal(err)
4245
}
@@ -57,7 +60,7 @@ func TestLinterRun(t *testing.T) {
5760
fmt.Println("Found issues: ", resultsSize)
5861
}
5962

60-
resultAllProblems, err := os.ReadFile(filepath.Join(outputDir, "report", "results", "result-allProblems.json"))
63+
resultAllProblems, err := os.ReadFile(filepath.Join(outputDir, "report", "result-allProblems.json"))
6164
if err != nil {
6265
t.Fatal("Error reading all problems file", err)
6366
}
@@ -67,38 +70,3 @@ func TestLinterRun(t *testing.T) {
6770
t.Fatal("All problems file is empty")
6871
}
6972
}
70-
71-
func deferredCleanup(path string) {
72-
err := os.RemoveAll(path)
73-
if err != nil {
74-
log.Fatal(err)
75-
}
76-
}
77-
78-
func createNativeProject(t *testing.T, name string) string {
79-
home, err := os.UserHomeDir()
80-
if err != nil {
81-
t.Fatal(err)
82-
}
83-
location := filepath.Join(home, ".qodana_scan_", name)
84-
err = gitClone("https://github.com/qodana/cpp-demo", location)
85-
if err != nil {
86-
t.Fatal(err)
87-
}
88-
return location
89-
}
90-
91-
func gitClone(repoURL, directory string) error {
92-
if _, err := os.Stat(directory); !os.IsNotExist(err) {
93-
err = os.RemoveAll(directory)
94-
if err != nil {
95-
return err
96-
}
97-
}
98-
cmd := exec.Command("git", "clone", repoURL, directory)
99-
err := cmd.Run()
100-
if err != nil {
101-
return err
102-
}
103-
return nil
104-
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

0 commit comments

Comments
 (0)