• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Sholtee / proxygen / 1005

17 Apr 2025 01:11PM UTC coverage: 91.501% (+1.3%) from 90.219%
1005

push

appveyor

Sholtee
greenify tests

5006 of 5471 relevant lines covered (91.5%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/SRC/Private/Extensions/UnitSyntaxFactoryBaseExtensions.cs
1
/********************************************************************************
2
* UnitSyntaxFactoryBaseExtensions.cs                                            *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Diagnostics;
8
using System.IO;
9
using System.Linq;
10
using System.Threading;
11

12
using Microsoft.CodeAnalysis;
13
using Microsoft.CodeAnalysis.CSharp.Syntax;
14

15
namespace Solti.Utils.Proxy.Internals
16
{
17
    internal static class UnitSyntaxFactoryBaseExtensions
18
    {
19
        public static SourceCode GetSourceCode(this UnitSyntaxFactoryBase src, in CancellationToken cancellation) => new
1✔
20
        (
1✔
21
            src.GetHint(),
1✔
22
            src.ResolveUnitAndDump(cancellation)
1✔
23
        );
1✔
24

25
        public static string GetHint(this UnitSyntaxFactoryBase src) => $"{src.ExposedClass}.cs";
1✔
26

27
        public static CompilationUnitSyntax ResolveUnitAndDump(this UnitSyntaxFactoryBase src, CancellationToken cancellation) 
28
        {
1✔
29
            CompilationUnitSyntax unit = src.ResolveUnit(null!, cancellation);
1✔
30

31
            string? sourceDump = src.Context.Config.SourceDump;
1✔
32

33
            if (sourceDump is not null)
1✔
34
            {
1✔
35
                string hint = src.GetHint();
1✔
36

37
                Directory.CreateDirectory(sourceDump);
1✔
38

39
                Log(Path.Combine(sourceDump, hint), unit.NormalizeWhitespace(eol: Environment.NewLine).ToFullString(), cancellation);
1✔
40

41
                if (src.Context.ReferenceCollector is not null)
1✔
42
                {
1✔
43
                    Log
1✔
44
                    (
1✔
45
                        Path.Combine(sourceDump, $"{hint}.references"),
1✔
46
                        string.Join
1✔
47
                        (
1✔
48
                            Environment.NewLine,
1✔
49
                            src
1✔
50
                                .Context
1✔
51
                                .ReferenceCollector
1✔
52
                                .References
1✔
53
                                .Select(static @ref => $"{@ref.Name}: {@ref.Location ?? "NULL"}")
×
54
                        ),
1✔
55
                        cancellation
1✔
56
                    );
1✔
57
                }
1✔
58

59
                static void Log(string file, string data, CancellationToken cancellation)  // TODO: implement real logging
60
                {
1✔
61
                    try
62
                    {
1✔
63
                        using StreamWriter log = File.CreateText(file);
1✔
64
                        log.AutoFlush = true;
1✔
65
                        log.Write(data, cancellation: cancellation);
1✔
66
                    }
1✔
67
                    catch (IOException ex)
×
68
                    {
×
69
                        Trace.TraceWarning($"File ({file}) could not be dumped: ${ex.Message}");
×
70
                    }
×
71
                }
1✔
72
            }
1✔
73

74
            return unit;
1✔
75
        }
1✔
76
    }
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc