FortuneN / FineCodeCoverage

Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too)
https://marketplace.visualstudio.com/items?itemName=FortuneNgwenya.FineCodeCoverage
Other
522 stars 40 forks source link

Generating runsettings from template fails with XmlException #310

Closed recomedia closed 1 year ago

recomedia commented 1 year ago

Installed product versions

Description

The solution (attached uses .NET Framework 4.0, which has been installed as part of VS Community 2019. It does so because the system that the final packages are deployed to runs an older mono version which supports only .NET Framework 4.0.

The solution (attached FCCException.zip) builds just fine. (Two warnings about being unable to sign the packages can be ignored, because these packages will l not even be used fo testing.)

The test cases execute just fine, but I get no code coverage. Instead, an exception stack trace shows up in the FCC part of the log:

Fine Code Coverage 03.12.2022 15:46:56: Exception generating runsettings from template System.Xml.XmlException: An error occurred while parsing EntityName. Line 5, position 54. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos) at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars) at System.Xml.XmlTextReaderImpl.FinishPartialValue() at System.Xml.XmlTextReaderImpl.get_Value() at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r) at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o) at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options) at FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage.RunSettingsTemplate.AddRecommendedYouDoNotChangeElementsIfNotProvided(String replacedRunSettingsTemplate, Boolean isNetFramework) at FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage.RunSettingsTemplate.ReplaceTemplate(String runSettingsTemplate, IRunSettingsTemplateReplacements replacements, Boolean isNetFramework) at FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage.TemplatedRunSettingsService.<>c__DisplayClass9_0.b0(ICoverageProject coverageProject) at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage.TemplatedRunSettingsService.d7.MoveNext()

Steps to recreate

  1. Unzip the attached solution FCCException.zip
  2. Open FCCException.sln in Visual Studio Community 2022
  3. From the Test Explorer, run all tests
  4. Look at the output from FCC

Current behavior

Throws the above exception and does not display code coverage

Expected behavior

If I am doing something wrong, give a meaningful error message.

Or, if all is fine, display the code coverage.

recomedia commented 1 year ago

Not sure wheter the upload really worked ... if you need me to upload the file again or at some other place, please let me know ...

tonyhallett commented 1 year ago

upload failed. Please try again or make available in a public repo.

tonyhallett commented 1 year ago

Did you provide your own run settings template ?

What are your exclude / include options ?

recomedia commented 1 year ago

Sorry for taking a while to react.

The zip archive is at http://share.recomedia.de/horst/FCCException.zip

I haven't been using my own runsettings file, relying on the default.

tonyhallett commented 1 year ago

Have you set up exclude / include options ?

recomedia commented 1 year ago

I don't think so, but, to be honest, I am not even sure where I would do that. If in the runsettings file, I don't have one.

tonyhallett commented 1 year ago

You would do that in the options page.

Have you successfully used FCC with a different project ?

recomedia commented 1 year ago

No, never used before. As I said, it could well be goofy me, but then a more helpful error message would be appreciated.

tonyhallett commented 1 year ago

Can you create a new dummy solution with a single test.

tonyhallett commented 1 year ago

Works on my machine ( after upgrading .Net version ),

image

Can you check that you do not have any rogue characters in your settings.

image

The settings can also come from your project files ( not with FCCException.sln ) or finecodecoverage-settings.xml files. Is there any chance that there could be one of these ?

Does your app data path contain the msCodeCoverage directory ? C:\Users\tonyh\AppData\Local\FineCodeCoverage\msCodeCoverage\17.1.0\build\netstandard1.0

tonyhallett commented 1 year ago

At some time today I will update FCC to write out the xml string causing XDocument.Parse to throw.

tonyhallett commented 1 year ago

FCC has been updated to write to the FCC output pane the string argument to XDocument.Parse. If you can show me this we can proceed.

recomedia commented 1 year ago

Thanks for the update. I have run it with the result shown below. Looks like FCC doesn't like the special character '&' in my path ... will try renaming the directory as a workaround ... yes, that helps.

Fine Code Coverage 12.12.2022 23:50:49: Initializing
Fine Code Coverage 12.12.2022 23:50:52: Initialized
Fine Code Coverage 12.12.2022 23:51:23: Exception generating runsettings from template
$System.Xml.XmlException: An error occurred while parsing EntityName. Line 5, position 54.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos)
   at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
   at System.Xml.XmlTextReaderImpl.FinishPartialValue()
   at System.Xml.XmlTextReaderImpl.get_Value()
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options)
   at FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage.RunSettingsTemplate.AddRecommendedYouDoNotChangeElementsIfNotProvided(String replacedRunSettingsTemplate, Boolean isNetFramework) 
Replaced template :
$<?xml version='1.0' encoding='utf-8'?>
<RunSettings>

  <RunConfiguration>
    <ResultsDirectory>C:\Users\Horst\Documents\Haus & Hof\FCCException\VisuWebNodesTest\bin\Debug\fine-code-coverage\coverage-tool-output</ResultsDirectory>
    <TestAdaptersPaths>C:\Users\Horst\AppData\Local\FineCodeCoverage\msCodeCoverage\17.1.0\build\netstandard1.0</TestAdaptersPaths>
    <CollectSourceInformation>False</CollectSourceInformation>
  </RunConfiguration>

  <DataCollectionRunSettings>

    <DataCollectors>

      <DataCollector friendlyName='Code Coverage' enabled='True'>

        <Configuration>

        <CodeCoverage>
            <ModulePaths>
              <Exclude>
                <ModulePath>C:\\Users\\Horst\\Documents\\Haus & Hof\\FCCException\\VisuWebNodesTest\\bin\\Debug\\VisuWebNodesTest.dll</ModulePath>
              </Exclude>
              <Include>

              </Include>
            </ModulePaths>
            <Functions>
              <Exclude>

              </Exclude>
              <Include>

              </Include>
            </Functions>
            <Attributes>
              <Exclude>

              </Exclude>
              <Include>

              </Include>
            </Attributes>
            <Sources>
              <Exclude>

              </Exclude>
              <Include>

              </Include>
            </Sources>
            <CompanyNames>
              <Exclude>

              </Exclude>
              <Include>

              </Include>
            </CompanyNames>
            <PublicKeyTokens>
              <Exclude>

              </Exclude>
              <Include>

              </Include>
            </PublicKeyTokens>
          </CodeCoverage>

          <Format>Cobertura</Format>
          <FCCGenerated/>
        </Configuration>

      </DataCollector>

    </DataCollectors>

  </DataCollectionRunSettings>

</RunSettings>
tonyhallett commented 1 year ago

I will escape the ampersand. Thanks

github-actions[bot] commented 1 year ago

released v1.1.191 and available on marketplace

recomedia commented 1 year ago

Thanks, FCC is now working flawlessly for me. Left you a coffee/beer or two ...

tonyhallett commented 1 year ago

Cheers