Skip to content
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Support for multiline string literals within compiler directives.
- Support for the `TEXTBLOCK` directive.
- **API:** `CompilerDirectiveParser` can now return a new `TextBlockDirective` type.
- **API:** `CheckVerifier::withCompilerVersion` method.
- **API:** `CheckVerifier::withToolchain` method.

### Changed

- `NativeInt` and `NativeUInt` are now treated as weak aliases in Delphi 12+.
- The length of open arrays is now modeled as `NativeInt` in Delphi 12+.
- Performance improvements.

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import au.com.integradev.delphi.builders.DelphiTestFile;
import au.com.integradev.delphi.builders.DelphiTestUnitBuilder;
import au.com.integradev.delphi.compiler.CompilerVersion;
import au.com.integradev.delphi.compiler.Toolchain;
import org.sonar.plugins.communitydelphi.api.check.DelphiCheck;

public interface CheckVerifier {
Expand All @@ -29,6 +31,10 @@ static CheckVerifier newVerifier() {

CheckVerifier withCheck(DelphiCheck check);

CheckVerifier withCompilerVersion(CompilerVersion compilerVersion);

CheckVerifier withToolchain(Toolchain toolchain);

CheckVerifier withUnitScopeName(String unitScope);

CheckVerifier withUnitAlias(String alias, String unitName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import au.com.integradev.delphi.builders.DelphiTestUnitBuilder;
import au.com.integradev.delphi.check.DelphiCheckContextImpl;
import au.com.integradev.delphi.check.MasterCheckRegistrar;
import au.com.integradev.delphi.compiler.CompilerVersion;
import au.com.integradev.delphi.compiler.Platform;
import au.com.integradev.delphi.compiler.Toolchain;
import au.com.integradev.delphi.file.DelphiFile.DelphiInputFile;
import au.com.integradev.delphi.preprocessor.DelphiPreprocessorFactory;
import au.com.integradev.delphi.preprocessor.directive.CompilerDirectiveParserImpl;
Expand Down Expand Up @@ -80,6 +82,8 @@ public class CheckVerifierImpl implements CheckVerifier {

private DelphiCheck check;
private DelphiTestFile testFile;
private CompilerVersion compilerVersion = DelphiProperties.COMPILER_VERSION_DEFAULT;
private Toolchain toolchain = DelphiProperties.COMPILER_TOOLCHAIN_DEFAULT;
private final Set<String> unitScopeNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
private final Map<String, String> unitAliases = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private final List<DelphiTestUnitBuilder> searchPathUnits = new ArrayList<>();
Expand All @@ -92,6 +96,18 @@ public CheckVerifier withCheck(DelphiCheck check) {
return this;
}

@Override
public CheckVerifier withCompilerVersion(CompilerVersion compilerVersion) {
this.compilerVersion = compilerVersion;
return this;
}

@Override
public CheckVerifier withToolchain(Toolchain toolchain) {
this.toolchain = toolchain;
return this;
}

@Override
public CheckVerifier withUnitScopeName(String unitScopeName) {
unitScopeNames.add(unitScopeName);
Expand Down Expand Up @@ -248,10 +264,7 @@ private List<Issue> execute() {
SymbolTable symbolTable =
SymbolTable.builder()
.preprocessorFactory(new DelphiPreprocessorFactory(Platform.WINDOWS))
.typeFactory(
new TypeFactoryImpl(
DelphiProperties.COMPILER_TOOLCHAIN_DEFAULT,
DelphiProperties.COMPILER_VERSION_DEFAULT))
.typeFactory(new TypeFactoryImpl(toolchain, compilerVersion))
.standardLibraryPath(standardLibraryPath)
.sourceFiles(List.of(file.getSourceCodeFile().toPath()))
.unitAliases(unitAliases)
Expand All @@ -267,7 +280,9 @@ private List<Issue> execute() {
var sensorContext = SensorContextTester.create(FileUtils.getTempDirectory());
sensorContext.settings().setProperty(DelphiProperties.TEST_TYPE_KEY, "Test.TTestSuite");

var compilerDirectiveParser = new CompilerDirectiveParserImpl(Platform.WINDOWS);
var compilerDirectiveParser =
new CompilerDirectiveParserImpl(
Platform.WINDOWS, file.getTextBlockLineEndingModeRegistry());

var checkRegistrar = mock(MasterCheckRegistrar.class);
when(checkRegistrar.getRuleKey(check))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@

import au.com.integradev.delphi.builders.DelphiTestUnitBuilder;
import au.com.integradev.delphi.checks.verifier.CheckVerifier;
import org.junit.jupiter.api.Test;
import au.com.integradev.delphi.compiler.CompilerVersion;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class PlatformDependentCastCheckTest {
@Test
void testPointerIntegerCastsShouldAddIssue() {
private static final String VERSION_ALEXANDRIA = "VER350";
private static final String VERSION_ATHENS = "VER360";

@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testPointerIntegerCastsShouldAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -40,10 +47,12 @@ void testPointerIntegerCastsShouldAddIssue() {
.verifyIssues();
}

@Test
void testObjectIntegerCastsShouldAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testObjectIntegerCastsShouldAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -57,10 +66,12 @@ void testObjectIntegerCastsShouldAddIssue() {
.verifyIssues();
}

@Test
void testInterfaceIntegerCastsShouldAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testInterfaceIntegerCastsShouldAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -74,10 +85,12 @@ void testInterfaceIntegerCastsShouldAddIssue() {
.verifyIssues();
}

@Test
void testNativeIntIntegerCastsShouldAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testNativeIntIntegerCastsShouldAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -91,10 +104,12 @@ void testNativeIntIntegerCastsShouldAddIssue() {
.verifyIssues();
}

@Test
void testNativeIntPointerCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testNativeIntPointerCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -108,10 +123,12 @@ void testNativeIntPointerCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testNativeIntObjectCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testNativeIntObjectCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -125,10 +142,12 @@ void testNativeIntObjectCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testNativeIntInterfaceCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testNativeIntInterfaceCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -142,10 +161,12 @@ void testNativeIntInterfaceCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testIntegerLiteralCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testIntegerLiteralCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -159,10 +180,12 @@ void testIntegerLiteralCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testHexadecimalLiteralCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testHexadecimalLiteralCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -176,10 +199,12 @@ void testHexadecimalLiteralCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testBinaryLiteralCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testBinaryLiteralCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -193,10 +218,12 @@ void testBinaryLiteralCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testTObjectStringCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testTObjectStringCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -210,10 +237,12 @@ void testTObjectStringCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testTObjectRecordCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testTObjectRecordCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendDecl("type")
Expand All @@ -230,10 +259,12 @@ void testTObjectRecordCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testRecordIntegerCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testRecordIntegerCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendDecl("type")
Expand All @@ -249,10 +280,12 @@ void testRecordIntegerCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testIntegerStringCastsShouldAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testIntegerStringCastsShouldAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -266,10 +299,12 @@ void testIntegerStringCastsShouldAddIssue() {
.verifyIssues();
}

@Test
void testNativeIntStringCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testNativeIntStringCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -283,10 +318,12 @@ void testNativeIntStringCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testIntegerArrayCastsShouldAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testIntegerArrayCastsShouldAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -300,10 +337,12 @@ void testIntegerArrayCastsShouldAddIssue() {
.verifyIssues();
}

@Test
void testNativeIntArrayCastsShouldNotAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testNativeIntArrayCastsShouldNotAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand All @@ -317,10 +356,12 @@ void testNativeIntArrayCastsShouldNotAddIssue() {
.verifyNoIssues();
}

@Test
void testStrongAliasCastsShouldAddIssue() {
@ParameterizedTest
@ValueSource(strings = {VERSION_ALEXANDRIA, VERSION_ATHENS})
void testStrongAliasCastsShouldAddIssue(String versionSymbol) {
CheckVerifier.newVerifier()
.withCheck(new PlatformDependentCastCheck())
.withCompilerVersion(CompilerVersion.fromVersionSymbol(versionSymbol))
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("procedure Foo;")
Expand Down
Loading