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
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ void RewriteSourceWithNewBaseline(string fileName, int lineNumber)
var fileInfo = _queryBaselineRewritingFileInfos.GetOrAdd(fileName, _ => new QueryBaselineRewritingFileInfo());
lock (fileInfo.Lock)
{
// Check if we've already processed this line - if so no need to do it again
if (fileInfo.ProcessedLines.Contains(lineNumber))
{
return;
}

fileInfo.ProcessedLines.Add(lineNumber);

// First, adjust our lineNumber to take into account any baseline rewriting that already occurred in this file
var origLineNumber = lineNumber;
foreach (var displacement in fileInfo.LineDisplacements)
Expand Down Expand Up @@ -239,13 +247,13 @@ void RewriteSourceWithNewBaseline(string fileName, int lineNumber)
// Skip over the invocation on the read side, and write the new baseline invocation
var tempBuf = new char[Math.Max(1024, invocation.Span.Length)];
reader.ReadBlock(tempBuf, 0, invocation.Span.Length);
var numNewlinesInOrigin = tempBuf.Count(c => c is '\n' or '\r');
var numNewlinesInOrigin = tempBuf.Count(c => c is '\n');

indentBuilder.Append(" ");
var indent = indentBuilder.ToString();
var newBaseLine = $@"AssertSql(
{string.Join("," + Environment.NewLine + indent + "//" + Environment.NewLine, SqlStatements.Select(sql => indent + "\"\"\"" + Environment.NewLine + sql + Environment.NewLine + "\"\"\""))})";
var numNewlinesInRewritten = newBaseLine.Count(c => c is '\n' or '\r');
var numNewlinesInRewritten = newBaseLine.Count(c => c is '\n');

writer.Write(newBaseLine);

Expand Down Expand Up @@ -338,6 +346,12 @@ public QueryBaselineRewritingFileInfo() { }

public object Lock { get; } = new();

/// <summary>
/// Contains information on which lines in the file where we've already performed baseline rewriting; we use this to
/// avoid processing the same line twice (e.g. when a test is a theory that's executed multiple times).
/// </summary>
public readonly HashSet<int> ProcessedLines = new();

/// <summary>
/// Contains information on where previous baseline rewriting caused line numbers to shift; this is used in adjusting line
/// numbers for later errors. The keys are (pre-rewriting) line numbers, and the values are offsets that have been applied to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ void RewriteSourceWithNewBaseline(string fileName, int lineNumber)
var fileInfo = _queryBaselineRewritingFileInfos.GetOrAdd(fileName, _ => new QueryBaselineRewritingFileInfo());
lock (fileInfo.Lock)
{
// Check if we've already processed this line - if so no need to do it again
if (fileInfo.ProcessedLines.Contains(lineNumber))
{
return;
}

fileInfo.ProcessedLines.Add(lineNumber);

// First, adjust our lineNumber to take into account any baseline rewriting that already occurred in this file
var origLineNumber = lineNumber;
foreach (var displacement in fileInfo.LineDisplacements)
Expand Down Expand Up @@ -255,13 +263,13 @@ void RewriteSourceWithNewBaseline(string fileName, int lineNumber)
// Skip over the invocation on the read side, and write the new baseline invocation
var tempBuf = new char[Math.Max(1024, invocation.Span.Length)];
reader.ReadBlock(tempBuf, 0, invocation.Span.Length);
var numNewlinesInOrigin = tempBuf.Count(c => c is '\n' or '\r');
var numNewlinesInOrigin = tempBuf.Count(c => c is '\n');

indentBuilder.Append(" ");
var indent = indentBuilder.ToString();
var newBaseLine = $@"Assert{(forUpdate ? "ExecuteUpdate" : "")}Sql(
{string.Join("," + Environment.NewLine + indent + "//" + Environment.NewLine, SqlStatements.Skip(offset).Take(count).Select(sql => indent + "\"\"\"" + Environment.NewLine + sql + Environment.NewLine + "\"\"\""))})";
var numNewlinesInRewritten = newBaseLine.Count(c => c is '\n' or '\r');
var numNewlinesInRewritten = newBaseLine.Count(c => c is '\n');

writer.Write(newBaseLine);

Expand Down Expand Up @@ -385,6 +393,12 @@ public QueryBaselineRewritingFileInfo() { }

public object Lock { get; } = new();

/// <summary>
/// Contains information on which lines in the file where we've already performed baseline rewriting; we use this to
/// avoid processing the same line twice (e.g. when a test is a theory that's executed multiple times).
/// </summary>
public readonly HashSet<int> ProcessedLines = new();

/// <summary>
/// Contains information on where previous baseline rewriting caused line numbers to shift; this is used in adjusting line
/// numbers for later errors. The keys are (pre-rewriting) line numbers, and the values are offsets that have been applied to
Expand Down