Skip to content

Commit 6986d85

Browse files
committed
add new "test" file type to the update feed to allow tests to be downloaded/updated
1 parent 4c53289 commit 6986d85

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

modules/DependencyControl.moon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class DependencyControl
130130

131131
@configFile = configFile or "#{@namespace}.json"
132132
@automationDir = @@automationDir[@type]
133+
@testDir = UnitTestSuite.testDir[@type]
133134
@version, err = @getVersionNumber version
134135
assert @version, msgs.new.badRecordError\format msgs.new.badRecord.badVersion\format err
135136

modules/DependencyControl/UnitTestSuite.moon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ class UnitTestSuite
754754

755755
@UnitTest = UnitTest
756756
@UnitTestClass = UnitTestClass
757+
@testDir = {macros: aegisub.decode_path("?user/automation/tests/DepUnit/macros"),
758+
modules: aegisub.decode_path("?user/automation/tests/DepUnit/modules")}
757759

758760
--- Creates a complete unit test suite for a module or automation script.
759761
-- Using this constructor will create all test classes and tests automatically.

modules/DependencyControl/Updater.moon

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class UpdateTask extends UpdaterBase
8282
moveFileFailed: "Failed to move '%s' ==> '%s': %s"
8383
updSuccess: "%s of %s '%s' (v%s) complete."
8484
reloadNotice: "Please rescan your autoload directory for the changes to take effect."
85+
unknownType: "Skipping file '%s': unknown type '%s'."
8586
}
8687
refreshRecord: {
8788
unsetVirtual: "Update initated by another macro already fetched %s '%s', switching to update mode."
@@ -282,23 +283,35 @@ class UpdateTask extends UpdaterBase
282283
@@logger\log msgs.performUpdate.updateReady, tmpDir
283284

284285
scriptSubDir = @record.moduleName and @record.moduleName\gsub("%.","/") or @record.namespace
285-
baseName, tmpBaseName = "#{@record.automationDir}/#{scriptSubDir}", "#{tmpDir}/#{scriptSubDir}"
286286

287287
dlm\clear!
288288
for file in *update.files
289+
file.type or= "script"
290+
289291
continue if file.delete
290-
tmpName, name, prettyName = tmpBaseName..file.name, baseName..file.name, scriptSubDir..file.name
292+
baseName = scriptSubDir .. file.name
293+
tmpName, prettyName = "#{tmpDir}/#{file.type}/#{baseName}", baseName
294+
switch file.type
295+
when "script"
296+
file.fullName = "#{@record.automationDir}/#{baseName}"
297+
when "test"
298+
file.fullName = "#{@record.testDir}/#{baseName}"
299+
prettyName ..= " (Unit Test)"
300+
else
301+
file.unknown = true
302+
@@logger\log msgs.performUpdate.unknownType, file.name, file.type
303+
continue
291304

292305
unless type(file.sha1)=="string" and #file.sha1 == 40 and tonumber(file.sha1, 16)
293306
return finish -35, "#{prettyName} (#{tostring(file.sha1)\lower!})"
294307

295-
if dlm\checkFileSHA1 name, file.sha1
308+
if dlm\checkFileSHA1 file.fullName, file.sha1
296309
@@logger\trace msgs.performUpdate.fileUnchanged, prettyName
297310
continue
298311

299312
dl, err = dlm\addDownload file.url, tmpName, file.sha1
300313
return finish -140, err unless dl
301-
dl.targetFile = name
314+
dl.targetFile = file.fullName
302315
@@logger\trace msgs.performUpdate.fileAddDownload, file.url, prettyName
303316

304317
dlm\waitForFinish (progress) ->
@@ -330,7 +343,7 @@ class UpdateTask extends UpdaterBase
330343
if #moveErrors>0
331344
return finish -50, @@logger\format moveErrors, 1
332345
else lfs.rmdir tmpDir
333-
os.remove baseName..file.name for file in *update.files when file.delete
346+
os.remove file.fullName for file in *update.files when file.delete and not file.unknown
334347

335348
-- Nuke old module refs and reload
336349
oldVer, wasVirtual = @record.version, @record.virtual

0 commit comments

Comments
 (0)