louthy / language-ext

C# functional language extensions - a base class library for functional programming
MIT License
6.42k stars 416 forks source link

Directory IO bug for Test when enumerating files #1298

Open janigbg opened 7 months ago

janigbg commented 7 months ago

When enumerating files, the files should be returned in a sequence using full path and file name. For the Test implementation, it seems to return each file as two entries; one with filename only, and one with last directory and filename.

Source in Microsoft docs: https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=net-7.0#system-io-directory-enumeratefiles(system-string-system-string)

Repro:

var path = "c:\\dir\\subdir";
var expected = Path.Combine(path, "file");
var computation =
    from dir in Directory<Runtime>.create(path)
    from file in File<Runtime>.writeAllText(expected, string.Empty)
    from files in Directory<Runtime>.enumerateFiles(path)
    select files;

var actual = (await computation.Run(Runtime.New()))
    .ThrowIfFail();

Assert.That(actual, Is.EquivalentTo(Seq1(expected)));

I get this result:

Assert.That(actual, Is.EquivalentTo(Seq1(expected)))
  Expected: equivalent to < "c:\dir\subdir\file" >
  But was:  < "subdir\file", "file" >
  Missing (1): < "c:\dir\subdir\file" >
  Extra (2): < "file", "subdir\file" >