Skip to content

Commit

Permalink
WI #2674 Adapt unit tests to run on Linux (#2690)
Browse files Browse the repository at this point in the history
- Codegen bug fix on node positions for generated node inserted after another node
- DOT graph output in cfg/dfa notifications does no longer include line breaks
- Formalized comments returned by LanguageServer are no longer formatted using line breaks from source code, clients must apply their own formatting depending on their display constraints
- Same goes for Hover data: tooltip texts are on a single line now
  • Loading branch information
fm-117 authored Jan 7, 2025
1 parent 8b21685 commit 1a19ef4
Show file tree
Hide file tree
Showing 90 changed files with 863 additions and 665 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ on:

jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]

runs-on: windows-latest
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
Expand All @@ -22,10 +25,10 @@ jobs:
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore .\TypeCobol.sln
run: dotnet restore ./TypeCobol.sln
- name: Build CSCup
run: dotnet build .\CSCup\CSCup.csproj --no-restore --configuration ${{ inputs.build-configuration }}
run: dotnet build ./CSCup/CSCup.csproj --no-restore --configuration ${{ inputs.build-configuration }}
- name: Build solution
run: dotnet build .\TypeCobol.sln --no-restore --configuration ${{ inputs.build-configuration }}
run: dotnet build ./TypeCobol.sln --no-restore --configuration ${{ inputs.build-configuration }}
- name: Test
run: dotnet test .\TypeCobol.sln --no-build --verbosity normal --configuration ${{ inputs.build-configuration }}
run: dotnet test ./TypeCobol.sln --no-build --verbosity normal --configuration ${{ inputs.build-configuration }}
4 changes: 2 additions & 2 deletions CLI/test/CLITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ internal static void ReadConsoleWarnings(string testFolderName, ReturnCode expec
string standardOutput = Test(workingDirectory, arguments, expectedReturnCode).Trim();
string warnings = string.Empty;

foreach (string line in standardOutput.Split(new string[] { "\r\n" }, StringSplitOptions.None))
foreach (string line in standardOutput.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None))
{
if (line.StartsWith("Line"))
warnings += line + "\r\n";
warnings += line + Environment.NewLine;
}

warnings = warnings.Trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* YPRTD20
* YCONVEA
* ).


DATA DIVISION.
Working-STORAGE SECTION.
Expand Down
2 changes: 1 addition & 1 deletion CLI/test/ressources/arguments_errors_1/ExpectedConsole.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Code: 124 TypeCobol.CLI: Missing copy path given is unreachable.
Code: 126 TypeCobol.CLI: The format 'BadFormat' is not supported. The input encoding 'BadInputEncoding' could not be found.
Code: 127 TypeCobol.CLI: Intrinsic files given are unreachable.
Code: 128 TypeCobol.CLI: Copies files given are unreachable.
Code: 129 TypeCobol.CLI: Dependencies files given are unreachable: input\MissingDependencies1
Code: 129 TypeCobol.CLI: Dependencies files given are unreachable: input/MissingDependencies1
Code: 130 TypeCobol.CLI: Maximum diagnostics have to be an integer.
Code: 131 TypeCobol.CLI: Unexpected parameter given for Output format option. Accepted parameters are Cobol85/0(default), PublicSignature/1.
Code: 132 TypeCobol.CLI: Expanding copy path given is unreachable.
Expand Down
2 changes: 1 addition & 1 deletion CLI/test/ressources/dependencies_4/ExpectedConsole.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Code: 129 TypeCobol.CLI: Dependencies files given are unreachable: input\DoesntExists.rdz.tcbl
Code: 129 TypeCobol.CLI: Dependencies files given are unreachable: input/DoesntExists.rdz.tcbl
Try TypeCobol.CLI --help for usage information.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Documentations":[{"__type":"DocumentationForProgram:#TypeCobol.Compiler.Nodes","Deprecated":"","Description":"My program \r\ndescription ","Name":"DocGen","Namespace":"DocGen","Needs":["some needs","description"],"ReplacedBy":"MyFonction2 ","Restriction":"Do not Use BOOL var ","See":"Thank you for your attention ","ToDos":["Add BOOL support","implement a call counter"]},{"__type":"DocumentationForType:#TypeCobol.Compiler.Nodes","Deprecated":"","Description":"inline typedef ","Name":"myType","Namespace":"DocGen","Restriction":"Do not Use BOOL var ","Visibility":1,"DocDataType":{"MaxOccurence":1,"Picture":"X(01)"}},{"__type":"DocumentationForType:#TypeCobol.Compiler.Nodes","Description":"Vect2D ","Name":"Vect2D","Namespace":"DocGen","Visibility":1,"Childrens":[{"Childrens":[{"DocDataType":{"MaxOccurence":1,"Picture":"9(4)"},"Name":"X"},{"DocDataType":{"MaxOccurence":1,"Picture":"9(4)"},"Name":"Y"}],"DocDataType":{"MaxOccurence":1},"Name":"Coord2d"}],"DocDataType":{"MaxOccurence":1}},{"__type":"DocumentationForFunction:#TypeCobol.Compiler.Nodes","Deprecated":"It is deprecated ","Description":"MyProc info \r\n","Name":"MyProc","Namespace":"DocGen","Needs":["long need"],"ToDos":["todo1","todo 2"],"Visibility":1,"Parameters":[{"DocDataType":{"MaxOccurence":1,"TypeName":"DATE"},"Info":"just a date","Name":"myDate","PassingType":0},{"DocDataType":{"MaxOccurence":1,"Picture":"S9(1)V9(12)"},"Info":"bla < 2","Name":"bla","PassingType":0},{"DocDataType":{"MaxOccurence":1,"TypeName":"BOOL"},"Name":"myBool","PassingType":2},{"DocDataType":{"MaxOccurence":1,"TypeName":"BOOL"},"Info":"toto","Name":"toto","PassingType":1},{"DocDataType":{"MaxOccurence":1,"Picture":"PPP999PPP"},"Name":"bli","PassingType":1}]}],"TypeCobolVersion":"[[ParserVersion]]"}
{"Documentations":[{"__type":"DocumentationForProgram:#TypeCobol.Compiler.Nodes","Deprecated":"","Description":"My program description","Name":"DocGen","Namespace":"DocGen","Needs":["some needs","description"],"ReplacedBy":"MyFonction2","Restriction":"Do not Use BOOL var","See":"Thank you for your attention","ToDos":["Add BOOL support","implement a call counter"]},{"__type":"DocumentationForType:#TypeCobol.Compiler.Nodes","Deprecated":"","Description":"inline typedef","Name":"myType","Namespace":"DocGen","Restriction":"Do not Use BOOL var","Visibility":1,"DocDataType":{"MaxOccurence":1,"Picture":"X(01)"}},{"__type":"DocumentationForType:#TypeCobol.Compiler.Nodes","Description":"Vect2D","Name":"Vect2D","Namespace":"DocGen","Visibility":1,"Childrens":[{"Childrens":[{"DocDataType":{"MaxOccurence":1,"Picture":"9(4)"},"Name":"X"},{"DocDataType":{"MaxOccurence":1,"Picture":"9(4)"},"Name":"Y"}],"DocDataType":{"MaxOccurence":1},"Name":"Coord2d"}],"DocDataType":{"MaxOccurence":1}},{"__type":"DocumentationForFunction:#TypeCobol.Compiler.Nodes","Deprecated":"It is deprecated","Description":"MyProc info","Name":"MyProc","Namespace":"DocGen","Needs":["long need"],"ToDos":["todo1","todo 2"],"Visibility":1,"Parameters":[{"DocDataType":{"MaxOccurence":1,"TypeName":"DATE"},"Info":"just a date","Name":"myDate","PassingType":0},{"DocDataType":{"MaxOccurence":1,"Picture":"S9(1)V9(12)"},"Info":"bla < 2","Name":"bla","PassingType":0},{"DocDataType":{"MaxOccurence":1,"TypeName":"BOOL"},"Name":"myBool","PassingType":2},{"DocDataType":{"MaxOccurence":1,"TypeName":"BOOL"},"Info":"toto","Name":"toto","PassingType":1},{"DocDataType":{"MaxOccurence":1,"Picture":"PPP999PPP"},"Name":"bli","PassingType":1}]}],"TypeCobolVersion":"[[ParserVersion]]"}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. STACKED.
DATA DIVISION.

WORKING-STORAGE SECTION.
01 TC-STACKED-FctList-Loaded PIC X(02) VALUE space.
88 TC-STACKED-FctList-IsLoaded VALUE 'OK'.
Expand All @@ -113,7 +113,7 @@
05 TC-STACKED-b4a83777-Idt PIC X(08) VALUE 'b4a83777'.
05 TC-STACKED-b4a83777 PROCEDURE-POINTER.


LINKAGE SECTION.
01 PntTab-Pnt POINTER.
01 TC-A1 PIC X.
Expand Down Expand Up @@ -161,7 +161,7 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. STACKED2.
DATA DIVISION.

WORKING-STORAGE SECTION.
01 TC-STACKED2-FctList-Loaded PIC X(02) VALUE space.
88 TC-STACKED2-FctList-IsLoaded VALUE 'OK'.
Expand All @@ -174,7 +174,7 @@
05 TC-STACKED2-f22bfcb0-Idt PIC X(08) VALUE 'f22bfcb0'.
05 TC-STACKED2-f22bfcb0 PROCEDURE-POINTER.


LINKAGE SECTION.
01 PntTab-Pnt POINTER.
01 TC-A1 PIC X.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM2.
DATA DIVISION.

WORKING-STORAGE SECTION.
01 TC-PGM2-FctList-Loaded PIC X(02) VALUE space.
88 TC-PGM2-FctList-IsLoaded VALUE 'OK'.
Expand All @@ -15,7 +15,7 @@
05 TC-PGM2-a4ee502d-Idt PIC X(08) VALUE 'a4ee502d'.
05 TC-PGM2-a4ee502d PROCEDURE-POINTER.


LINKAGE SECTION.
01 PntTab-Pnt POINTER.
01 TC-A1 PIC X.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*REMARKS. COPY=(
* TESTCPY
* ).

data division.
working-storage section.
*01 MyType typedef strict public.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* XMYCOPY
* YMYCOPY1
* ).


ENVIRONMENT DIVISION.
DATA DIVISION.
Expand Down
19 changes: 8 additions & 11 deletions Codegen/src/Actions/Qualifier.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TypeCobol.Codegen.Nodes;
using TypeCobol.Codegen.Nodes;
using TypeCobol.Compiler.CodeElements;
using TypeCobol.Compiler.CodeModel;
using TypeCobol.Compiler.Nodes;
Expand Down Expand Up @@ -112,7 +109,7 @@ public override bool Visit(StorageArea storageArea)
{
if (this.CurrentNode.IsFlagSet(Node.Flag.NodeContainsIndex) || this.CurrentNode.IsFlagSet(Node.Flag.NodeContainsBoolean))
{
Tuple<int, int, int, List<int>, List<int>> sourcePositions = this.Generator.FromToPositions(this.CurrentNode);
NodePositions sourcePositions = this.Generator.FromToPositions(this.CurrentNode);
foreach (TypeCobol.Compiler.CodeElements.StorageArea storage_area in this.CurrentNode.QualifiedStorageAreas.Keys)
{
if (this.CurrentNode.IsFlagSet(Node.Flag.NodeContainsIndex))
Expand All @@ -130,7 +127,7 @@ public override bool Visit(StorageArea storageArea)
return true;
}

private void QualifiedStorageAreaSelecterForBoolean(StorageArea storage_area, Tuple<int, int, int, List<int>, List<int>> sourcePositions)
private void QualifiedStorageAreaSelecterForBoolean(StorageArea storage_area, NodePositions sourcePositions)
{
if (UsedStorageArea != null && UsedStorageArea.Contains(storage_area))
return;
Expand All @@ -147,7 +144,7 @@ private void QualifiedStorageAreaSelecterForBoolean(StorageArea storage_area, Tu
UsedStorageArea.Add(storage_area);
}

private void QualifiedStorageAreaSelecterForIndexes(StorageArea storageArea, Tuple<int, int, int, List<int>, List<int>> sourcePositions)
private void QualifiedStorageAreaSelecterForIndexes(StorageArea storageArea, NodePositions sourcePositions)
{
if (storageArea.SymbolReference != null && !storageArea.SymbolReference.IsQualifiedReference)
{
Expand Down Expand Up @@ -257,7 +254,7 @@ public override bool Visit(IndexDefinition indexDefinition)
{
if (index.Name.Equals(indexDefinition.Name))
{
Tuple<int, int, int, List<int>, List<int>> sourcePositions = this.Generator.FromToPositions(indexDefinition.Parent);
NodePositions sourcePositions = this.Generator.FromToPositions(indexDefinition.Parent);
string qualified_name = indexDefinition.QualifiedName.ToString();
GenerateToken item = null;
string hashName = GeneratorHelper.ComputeIndexHashName(qualified_name, indexDefinition.Parent);
Expand Down Expand Up @@ -558,7 +555,7 @@ internal void Perform(Node sourceNode)

//Now this Node Is Visited
sourceNode.SetFlag(Node.Flag.HasBeenTypeCobolQualifierVisited, true);
Tuple<int, int, int, List<int>, List<int>> sourcePositions = this.Generator.FromToPositions(sourceNode);
NodePositions sourcePositions = this.Generator.FromToPositions(sourceNode);
IList<TypeCobol.Compiler.Scanner.Token> nodeTokens = sourceNode.CodeElement.ConsumedTokens;
List<Tuple<int, int>> boundaries = ItemsListIndexBoundary(nodeTokens);
int b = 0;
Expand Down Expand Up @@ -724,7 +721,7 @@ internal class GenerateToken : GenericNode<CodeElement>, GeneratedAndReplace
/// <param name="codelement">The Code element of this Node</param>
/// <param name="code">The replace code</param>
/// <param name="sourcePositions">The Positions of the Source Node</param>
public GenerateToken(CodeElement codelement, string code, Tuple<int, int, int, List<int>, List<int>> sourcePositions)
public GenerateToken(CodeElement codelement, string code, NodePositions sourcePositions)
: base(codelement)
{
ReplaceCode = code;
Expand All @@ -734,7 +731,7 @@ public GenerateToken(CodeElement codelement, string code, Tuple<int, int, int, L
/// <summary>
/// Source Node Positions
/// </summary>
public Tuple<int, int, int, List<int>, List<int>> SourceNodePositions
public NodePositions SourceNodePositions
{
get;
private set;
Expand Down
9 changes: 2 additions & 7 deletions Codegen/src/Codegen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Antlr4.Runtime" Version="4.6.6" />
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="TypeCobol.TemplateTask" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" PrivateAssets="all" />
<PackageReference Include="TypeCobol.TemplateTask" Version="1.3.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 12 additions & 12 deletions Codegen/src/Generator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Diagnostics;
using TypeCobol.Codegen.Actions;
using TypeCobol.Codegen.Nodes;
using TypeCobol.Compiler;
Expand All @@ -17,6 +13,15 @@

namespace TypeCobol.Codegen
{
/// <summary>
/// Capture positions for actual or generated nodes.
/// </summary>
/// <param name="From">Start position of the node.</param>
/// <param name="To">End position of the node.</param>
/// <param name="Span">End offset of the node, this is the end column of the node on its last line.</param>
/// <param name="LineNumbers">List of line numbers the node spans across.</param>
public record NodePositions(int From, int To, int Span, List<int> LineNumbers);

/// <summary>
/// The Second Code Generator which can Handle correctly all preprocessor directives
/// during the Code Generation Phase.
Expand Down Expand Up @@ -149,7 +154,7 @@ public Generator(TypeCobol.Compiler.CompilationDocument document, StringBuilder
/// The method also calculate the ending span offset from the beginning of the last line.
/// It also get the list of Line numbers occupated by this node, and the offset of each line.
/// </summary>
public Tuple<int, int, int, List<int>, List<int>> FromToPositions(Node node)
public NodePositions FromToPositions(Node node)
{
if (node.CodeElement == null || node.CodeElement.ConsumedTokens == null || node is ParameterEntry)
return null;
Expand All @@ -161,7 +166,6 @@ public Tuple<int, int, int, List<int>, List<int>> FromToPositions(Node node)
int i = 0;
int span = 0;
List<int> lineNumbers = new List<int>();
List<int> lineOffsets = new List<int>();
SourceDocument.SourceLine srcFirstLine = null;
do
{
Expand All @@ -180,15 +184,12 @@ public Tuple<int, int, int, List<int>, List<int>> FromToPositions(Node node)
while (++lastLine < curLineIndex)
{
lineNumbers.Add(lastLine);
SourceDocument.SourceLine srcLine = TargetDocument[lastLine - 1];
if (srcFirstLine != null) lineOffsets.Add(srcLine.From - srcFirstLine.From);
}
}
SourceDocument.SourceLine curLine = TargetDocument[curLineIndex - 1];
if (srcFirstLine == null)
srcFirstLine = curLine;
lineNumbers.Add(curLineIndex);
lineOffsets.Add(curLine.From - srcFirstLine.From);
span = 0;
while ((i < node.CodeElement.ConsumedTokens.Count) && ((curLineIndex == node.CodeElement.ConsumedTokens[i].Line)
|| (node.CodeElement.ConsumedTokens[i] is TypeCobol.Compiler.Preprocessor.ImportedToken)))
Expand All @@ -209,8 +210,7 @@ public Tuple<int, int, int, List<int>, List<int>> FromToPositions(Node node)
}
} while (i < node.CodeElement.ConsumedTokens.Count);
lineNumbers.TrimExcess();
lineOffsets.TrimExcess();
return new Tuple<int, int, int, List<int>, List<int>>(from, to, span, lineNumbers, lineOffsets);
return new NodePositions(from, to, span, lineNumbers);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Codegen/src/Generators/DefaultGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ protected SourceText LinearGeneration<A>(LinearNodeSourceCodeMapper mapper, Line
//Pad a splitted segment
if (mapper.Nodes[node_index].Positions != null)
{
int span = mapper.Nodes[node_index].Positions.Item3;
int span = mapper.Nodes[node_index].Positions.Span;
string pad = new string(' ', span);
curSourceText.Insert(pad, to.Pos, to.Pos);
}
Expand Down
Loading

0 comments on commit 1a19ef4

Please sign in to comment.