-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added e2e tests for creating a new file and project. The tests expect the `qtcli` binary to be located under the `tests/` directory. The documentation and .gitignore have been updated accordingly.
- Loading branch information
Showing
6 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
dist/ | ||
tests/qtcli | ||
tests/qtcli.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module qtcli-e2e | ||
|
||
go 1.23.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2025 The Qt Company Ltd. | ||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only | ||
|
||
package e2e | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestNewFile(t *testing.T) { | ||
name := "myfile" | ||
exts := []string{"qrc", "qml", "ts", "ui"} | ||
|
||
for _, ext := range exts { | ||
checker := func(workingDir string) { | ||
fileName := name + "." + ext | ||
fullPath := filepath.Join(workingDir, fileName) | ||
CheckFileExists(t, fullPath) | ||
} | ||
|
||
t.Run(ext, func(t *testing.T) { | ||
args := []string{ | ||
"new-file", name, | ||
"--preset", "@types/" + ext, | ||
} | ||
|
||
RunQtcli(t, checker, args...) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2025 The Qt Company Ltd. | ||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only | ||
|
||
package e2e | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
type ProjectPreset struct { | ||
name string | ||
expectedFiles []string | ||
} | ||
|
||
func TestNewProject(t *testing.T) { | ||
projectName := "myapp" | ||
presets := []ProjectPreset{ | ||
{"cpp/console", []string{"CMakeLists.txt", "main.cpp"}}, | ||
{"cpp/qtquick", []string{"CMakeLists.txt", "main.cpp", "Main.qml"}}, | ||
{"cpp/qwidget", []string{ | ||
"CMakeLists.txt", "main.cpp", | ||
"widget.cpp", "widget.h", "widget.ui", | ||
}}, | ||
} | ||
|
||
for _, preset := range presets { | ||
checker := func(workingDir string) { | ||
projectDir := filepath.Join(workingDir, projectName) | ||
CheckDirHasFiles(t, projectDir, preset.expectedFiles) | ||
} | ||
|
||
t.Run(preset.name, func(t *testing.T) { | ||
args := []string{ | ||
"new", projectName, | ||
"--preset", "@projects/" + preset.name, | ||
} | ||
|
||
RunQtcli(t, checker, args...) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (C) 2025 The Qt Company Ltd. | ||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only | ||
|
||
package e2e | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func RunQtcli(t *testing.T, checker func(string), args ...string) { | ||
t.Helper() | ||
|
||
cwd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatal("cannot determine current workding directory") | ||
} | ||
|
||
qtcliPath := filepath.Join(cwd, "..", "qtcli") | ||
tempDir, err := os.MkdirTemp(cwd, "qtcli-e2e-") | ||
if err != nil { | ||
t.Fatal("cannot make temporal directory to run a test") | ||
} | ||
|
||
defer os.RemoveAll(tempDir) | ||
cmd := exec.Command(qtcliPath, args...) | ||
cmd.Dir = tempDir | ||
|
||
if err := cmd.Run(); err != nil { | ||
t.Fatalf("cannot run command: %v", err) | ||
} | ||
|
||
checker(tempDir) | ||
} | ||
|
||
func CheckFileExists(t *testing.T, fullPath string) { | ||
t.Helper() | ||
s, err := os.Stat(fullPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if s.IsDir() { | ||
t.Fatalf("found a directory instead of a file: %v", fullPath) | ||
} | ||
|
||
if s.Size() == 0 { | ||
t.Fatalf("found but has no content: %v", fullPath) | ||
} | ||
} | ||
|
||
func CheckDirExists(t *testing.T, fullPath string) { | ||
t.Helper() | ||
s, err := os.Stat(fullPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !s.IsDir() { | ||
t.Fatalf("found a file instead of a directory: %v", fullPath) | ||
} | ||
} | ||
|
||
func CheckDirHasFiles(t *testing.T, dir string, files []string) { | ||
t.Helper() | ||
CheckDirExists(t, dir) | ||
|
||
for _, file := range files { | ||
CheckFileExists(t, filepath.Join(dir, file)) | ||
} | ||
} |