]> gitweb.factorcode.org Git - factor.git/commitdiff
vocabs.metadata.resources: new error resource-missing, if a resources.txt line doesnt...
authorBjörn Lindqvist <bjourne@gmail.com>
Tue, 13 Sep 2016 04:07:14 +0000 (06:07 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Tue, 13 Sep 2016 04:07:14 +0000 (06:07 +0200)
So then if files declared in resources.txt are missing, that will
hopefully be caught by the deploy process.

basis/vocabs/metadata/resources/resources-tests.factor
basis/vocabs/metadata/resources/resources.factor

index afb0d2ad733c15de69f878d85072fccca7bf39ac..81955100650e22cfba5ed2e220c1bc87ec5cd954 100644 (file)
@@ -2,11 +2,15 @@
 USING: arrays globs sorting tools.test vocabs.metadata.resources ;
 IN: vocabs.metadata.resources.tests
 
-! filter-resources
+! match-pattern
 { { "hello.txt" } } [
-    "*.txt" <glob> 1array { "hello.txt" } filter-resources
+    "*.txt" { "hello.txt" } match-pattern
 ] unit-test
 
+[
+    "*.txt" { "foo.bar" "foo.factor" } match-pattern
+] [ resource-missing? ] must-fail-with
+
 ! vocab-resource-files
 { { "bar" "bas" "foo" } }
 [ "vocabs.metadata.resources.test.1" vocab-resource-files natural-sort ] unit-test
index 635bd4cc3f4c90c2db28eefbf2e67b2c738b3a46..24f0e8a7ec13f4af4a273d1e40aab5d1e70b0d85 100644 (file)
@@ -1,6 +1,7 @@
 ! (c)2010 Joe Groff bsd license
-USING: globs io.directories io.directories.hierarchy io.files.info
-io.pathnames kernel regexp sequences vocabs.loader vocabs.metadata ;
+USING: fry globs io.directories io.directories.hierarchy io.files.info
+io.pathnames kernel regexp sequences sets vocabs.loader
+vocabs.metadata ;
 IN: vocabs.metadata.resources
 
 <PRIVATE
@@ -21,13 +22,19 @@ PRIVATE>
         dup directory-tree-files [ append-path ] with map
     ] [ drop { } ] if swap prefix ;
 
-: filter-resources ( resource-globs vocab-files -- vocab-files' )
-    [ swap [ matches? ] with any? ] with filter ;
+ERROR: resource-missing pattern ;
+
+: match-pattern ( pattern files -- files' )
+    over <glob> '[ _ matches? ] filter
+    [ resource-missing ] [ nip ] if-empty ;
+
+: match-patterns ( patterns files -- files' )
+    '[ _ match-pattern ] map concat members ;
 
 : vocab-resource-files ( vocab -- filenames )
-    [ vocab-resources [ <glob> ] map ] [ vocab-dir-in-root ] bi
+    [ vocab-resources ] [ vocab-dir-in-root ] bi
     [
-        filter-resources [ expand-resource ] map concat
+        match-patterns [ expand-resource ] map concat
     ] with-directory-files ;
 
 : copy-vocab-resources ( dir vocab -- )