Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Swift integration tests to pytest. #17178

Merged
merged 6 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion swift/ql/integration-tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
py_library(
name = "utils",
srcs = [
"create_database_utils.py",
"diagnostics_test_utils.py",
],
visibility = ["//swift:__subpackages__"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import runs_on


@(runs_on.linux or runs_on.windows)
def test(codeql, swift):
codeql.database.create(_assert_failure=True)
41 changes: 0 additions & 41 deletions swift/ql/integration-tests/create_database_utils.py

This file was deleted.

1 change: 0 additions & 1 deletion swift/ql/integration-tests/legacy

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
import runs_on

run_codeql_database_create([
"swiftc -enable-bare-slash-regex regex.swift -o /dev/null",
], lang="swift")

@runs_on.linux
def test(codeql, swift):
codeql.database.create(command="swiftc -enable-bare-slash-regex regex.swift -o /dev/null")

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
from diagnostics_test_utils import *
import runs_on

run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully)
check_diagnostics()

@runs_on.macos
def test(codeql, swift):
codeql.database.create(_assert_failure=True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
from diagnostics_test_utils import *
import runs_on

run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully)
check_diagnostics()

@runs_on.macos
def test(codeql, swift):
codeql.database.create(_assert_failure=True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
from diagnostics_test_utils import *
import runs_on

run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully)
check_diagnostics()

@runs_on.macos
def test(codeql, swift):
codeql.database.create(_assert_failure=True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
from diagnostics_test_utils import *
import runs_on

run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully)
check_diagnostics()

@runs_on.macos
def test(codeql, swift):
codeql.database.create(_assert_failure=True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
from diagnostics_test_utils import *
import runs_on

run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully)
check_diagnostics()

@runs_on.macos
def test(codeql, swift):
codeql.database.create(_assert_failure=True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
from diagnostics_test_utils import *
import runs_on

run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully)
check_diagnostics()

@runs_on.macos
def test(codeql, swift):
codeql.database.create(_assert_failure=True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
from diagnostics_test_utils import *
import runs_on

run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully)
check_diagnostics()

@runs_on.macos
def test(codeql, swift):
codeql.database.create(_assert_failure=True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from create_database_utils import *
import runs_on
import pytest

runSuccessfully(['xcodebuild', 'clean'])
runSuccessfully(['swift', 'package', 'clean'])
run_codeql_database_create([], lang='swift', keep_trap=True)

@runs_on.macos
@pytest.mark.ql_test("DB-CHECK", xfail=True)
def test(codeql, swift):
codeql.database.create()
9 changes: 5 additions & 4 deletions swift/ql/integration-tests/osx-only/canonical-case/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from create_database_utils import *
import runs_on

run_codeql_database_create([
'./build.sh',
], lang='swift')

@runs_on.macos
def test(codeql, swift):
codeql.database.create(command="./build.sh")
20 changes: 12 additions & 8 deletions swift/ql/integration-tests/osx-only/hello-xcode/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from create_database_utils import *
import runs_on
import pytest

run_codeql_database_create([
'xcodebuild clean',
'xcodebuild build '
'-project codeql-swift-autobuild-test.xcodeproj '
'-target codeql-swift-autobuild-test '
'CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO',
], lang='swift', keep_trap=True)

@runs_on.macos
@pytest.mark.ql_test("DB-CHECK", xfail=True)
def test(codeql, swift):
codeql.database.create(
command="xcodebuild build "
"-project codeql-swift-autobuild-test.xcodeproj "
"-target codeql-swift-autobuild-test "
"CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO",
)
12 changes: 7 additions & 5 deletions swift/ql/integration-tests/posix-only/cross-references/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from create_database_utils import *
import runs_on
import pytest

run_codeql_database_create([
'swift package clean',
'swift build'
], lang='swift')

@runs_on.posix
@pytest.mark.ql_test("DB-CHECK", xfail=True)
def test(codeql, swift):
codeql.database.create(command="swift build")
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
| Builtin.Executor | BuiltinExecutorType |
| Builtin.FPIEEE32 | BuiltinFloatType |
| Builtin.FPIEEE64 | BuiltinFloatType |
| Builtin.FPIEEE80 | BuiltinFloatType |
| Builtin.Int1 | BuiltinIntegerType |
| Builtin.Int8 | BuiltinIntegerType |
| Builtin.Int16 | BuiltinIntegerType |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ import swift

from BuiltinType t
// FPIEEE16 related stuff is not there on macOS
where not t.toString().matches("%FPIEEE16")
// FPIEEE80 is also missing on some CI runners
where
not t.toString().matches("%FPIEEE16") and
not t.toString().matches("%FPIEEE80")
select t, t.getPrimaryQlClasses()
10 changes: 5 additions & 5 deletions swift/ql/integration-tests/posix-only/deduplication/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from create_database_utils import *
import runs_on

run_codeql_database_create([
'swift package clean',
'swift build',
], lang='swift', keep_trap=True)

@runs_on.posix
def test(codeql, swift):
codeql.database.create(command="swift build", keep_trap=True)
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from create_database_utils import *
from subprocess import check_call
from hashlib import sha256
from pathlib import Path
import runs_on
import pytest

run_codeql_database_create([
'./build.sh',
], lang='swift',
)

with open('hashes.expected', 'w') as expected:
for f in sorted(Path().glob("*.swiftmodule")):
with open(f, 'rb') as module:
print(f.name, sha256(module.read()).hexdigest(), file=expected)
@runs_on.posix
@pytest.mark.ql_test("DB-CHECK", xfail=True)
def test(codeql, swift, expected_files):
codeql.database.create(command="./build.sh")
with open("hashes.expected", "w") as expected:
for f in sorted(Path().glob("*.swiftmodule")):
with open(f, "rb") as module:
print(f.name, sha256(module.read()).hexdigest(), file=expected)

with open('hashes.actual', 'w') as actual:
hashes = [(s.name, s.resolve().name) for s in Path("test-db/working/swift-extraction-artifacts/store").iterdir()]
hashes.sort()
for module, hash in hashes:
print(module, hash, file=actual)

check_call(['diff', '-u', 'hashes.expected', 'hashes.actual'])
with open("hashes.actual", "w") as actual:
hashes = [
(s.name, s.resolve().name)
for s in Path("test-db/working/swift-extraction-artifacts/store").iterdir()
]
hashes.sort()
for module, hash in hashes:
print(module, hash, file=actual)
expected_files.add("hashes.expected")
10 changes: 5 additions & 5 deletions swift/ql/integration-tests/posix-only/hello-world/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from create_database_utils import *
import runs_on

run_codeql_database_create([
'swift package clean',
'swift build'
], lang='swift')

@runs_on.posix
def test(codeql, swift):
codeql.database.create(command="swift build")
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from create_database_utils import *
import runs_on
import pytest

run_codeql_database_create([
'./build.sh',
], lang='swift', keep_trap=True)

@runs_on.posix
@pytest.mark.ql_test("DB-CHECK", xfail=True)
def test(codeql, swift):
codeql.database.create(command="./build.sh")
12 changes: 7 additions & 5 deletions swift/ql/integration-tests/posix-only/partial-modules/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from create_database_utils import *
import runs_on
import pytest

run_codeql_database_create([
'swift package clean',
'swift build'
], lang='swift', keep_trap=True)

@runs_on.posix
@pytest.mark.ql_test("DB-CHECK", xfail=True)
def test(codeql, swift):
codeql.database.create(command="swift build")
33 changes: 17 additions & 16 deletions swift/ql/integration-tests/posix-only/symlinks/test.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from create_database_utils import *
import os
import runs_on
import pytest

symlinks = ['preserve/Sources/A.swift', 'resolve/Sources/A.swift']

for s in symlinks:
try:
os.symlink(os.getcwd() + '/main.swift', s)
except:
pass
@runs_on.posix
@pytest.mark.ql_test("DB-CHECK", xfail=True)
def test(codeql, swift):
symlinks = ["preserve/Sources/A.swift", "resolve/Sources/A.swift"]

run_codeql_database_create([
'swift package clean --package-path resolve',
'swift build --package-path resolve',
'swift package clean --package-path preserve',
'env CODEQL_PRESERVE_SYMLINKS=true swift build --package-path preserve'
], lang='swift', keep_trap=True)

for s in symlinks:
os.unlink(s)
for s in symlinks:
try:
os.symlink(os.getcwd() + "/main.swift", s)
except:
pass
codeql.database.create(
command=[
"swift build --package-path resolve",
"env CODEQL_PRESERVE_SYMLINKS=true swift build --package-path preserve",
]
)
4 changes: 0 additions & 4 deletions swift/ql/integration-tests/qlpack.yml

This file was deleted.

Loading
Loading