Skip to content

Commit

Permalink
Port Swift integration tests to pytest.
Browse files Browse the repository at this point in the history
  • Loading branch information
criemen committed Aug 7, 2024
1 parent ef21ee5 commit 2e1bc46
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 246 deletions.
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
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")
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.linux
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,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 *
import runs_on

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

@runs_on.macos
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")
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")
36 changes: 19 additions & 17 deletions swift/ql/integration-tests/posix-only/frontend-invocations/test.py
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")
11 changes: 7 additions & 4 deletions swift/ql/integration-tests/posix-only/linkage-awareness/test.py
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

0 comments on commit 2e1bc46

Please sign in to comment.