@@ -63,6 +63,57 @@ func TestSymlinkLoop(t *testing.T) {
6363 assert .Panics (t , func () { FindProjects () }, "Infinite symlink loop encountered during project discovery" )
6464}
6565
66+ func TestBrokenSymlink (t * testing.T ) {
67+ projectsPath := testDataPath .Join ("Projects" )
68+ symlinkPath := projectsPath .Join ("test-symlink" )
69+ symlinkTargetPath := projectsPath .Join ("nonexistent" )
70+ // The broken symlink must have the attributes of a folder in order to be effective in this test, so the target must
71+ // exist at the time the symlink is created.
72+ err := symlinkTargetPath .Mkdir ()
73+ require .Nil (t , err )
74+ // Create a folder symlink in the projects folder.
75+ // It's probably most friendly to developers using Windows to create the symlink needed for the test on demand.
76+ err = os .Symlink (projectsPath .Join ("nonexistent" ).String (), symlinkPath .String ())
77+ require .Nil (t , err , "This test must be run as administrator on Windows to have symlink creation privilege." )
78+ defer symlinkPath .RemoveAll () // Clean up.
79+
80+ // Break the symlink.
81+ err = symlinkTargetPath .Remove ()
82+ require .Nil (t , err )
83+
84+ flags := test .ConfigurationFlags ()
85+ flags .Set ("project-type" , "all" )
86+ flags .Set ("recursive" , "true" )
87+ configuration .Initialize (flags , []string {projectsPath .String ()})
88+
89+ foundProjects , err := FindProjects ()
90+ require .Nil (t , err )
91+ assert .True (
92+ t ,
93+ reflect .DeepEqual (
94+ foundProjects ,
95+ []Type {
96+ {
97+ Path : testDataPath .Join ("Projects" , "Library" ),
98+ ProjectType : projecttype .Library ,
99+ SuperprojectType : projecttype .Library ,
100+ },
101+ {
102+ Path : testDataPath .Join ("Projects" , "Library" , "examples" , "Example" ),
103+ ProjectType : projecttype .Sketch ,
104+ SuperprojectType : projecttype .Library ,
105+ },
106+ {
107+ Path : testDataPath .Join ("Projects" , "Sketch" ),
108+ ProjectType : projecttype .Sketch ,
109+ SuperprojectType : projecttype .Sketch ,
110+ },
111+ },
112+ ),
113+ "Broken symlink encountered during project discovery" ,
114+ )
115+ }
116+
66117func TestFindProjects (t * testing.T ) {
67118 sketchPath := testDataPath .Join ("Sketch" )
68119 libraryPath := testDataPath .Join ("Library" )
0 commit comments