Commits

Taku Miyakawa committed 88029bb

Renames SCOPE_GUARD module to GUARD (closing issue #486)

  • Participants
  • Parent commits 41c73c1

Comments (0)

Files changed (7)

File src/main/kink/GUARD.kn

+#!/usr/bin/env kink
+# vim: et sw=4 sts=4
+
+# Copyright (c) 2013 Miyakawa Taku
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+:guarding = { (:_block)
+    :Scope_guard = Scope_proto.child('Actions' [])
+    { _block(Scope_guard) } .try.switch(
+        [true :Result] {
+            Scope_guard.:result = const_fun(Result)
+            Scope_guard._after_success
+        }
+        [false :Exception] {
+            Scope_guard.:exception = const_fun(Exception)
+            Scope_guard._after_failure
+        }
+    )
+}
+
+:Scope_proto = value(
+    'Actions' []
+    'on_exit' { > :Scope_guard (:_block)
+        Scope_guard.Actions.push(_exit_action($_block))
+        Scope_guard
+    }
+    'on_success' { > :Scope_guard (:_block)
+        Scope_guard.Actions.push(_success_action($_block))
+        Scope_guard
+    }
+    'on_failure' { > :Scope_guard (:_block)
+        Scope_guard.Actions.push(_failure_action($_block))
+        Scope_guard
+    }
+    'auto_close' { > :Scope_guard (:Closeable)
+        Scope_guard.on_exit { Closeable.close }
+        Closeable
+    }
+    '_after_success' { > :Scope_guard
+        Scope_guard.Actions.empty?.then {
+            Scope_guard.result
+        } {
+            :Action = Scope_guard.Actions.pop
+            { Action.act_for_success } .try.switch(
+                [true :Result] {
+                    Scope_guard._after_success
+                }
+                [false :Exception] {
+                    Scope_guard.:exception = const_fun(Exception)
+                    Scope_guard._after_failure
+                }
+            )
+        }
+    }
+    '_after_failure' { > :Scope_guard
+        { Scope_guard.Actions.any? } .loop {
+            :Action = Scope_guard.Actions.pop
+            { Action.act_for_failure } .try.switch(
+                [false :New_exception] {
+                    Scope_guard.exception.addSuppressed(New_exception)
+                }
+            )
+        }
+        Scope_guard.exception.throw
+    }
+)
+
+:_exit_action = { (:_block)
+    value(
+        'act_for_failure' $_block
+        'act_for_success' $_block
+    )
+}
+
+:_success_action = { (:_block)
+    value(
+        'act_for_failure' {}
+        'act_for_success' $_block
+    )
+}
+
+:_failure_action = { (:_block)
+    value(
+        'act_for_failure' $_block
+        'act_for_success' {}
+    )
+}

File src/main/kink/SCOPE_GUARD.kn

-#!/usr/bin/env kink
-# vim: et sw=4 sts=4
-
-# Copyright (c) 2013 Miyakawa Taku
-# 
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-# 
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-:guarding = { (:_block)
-    :Scope_guard = Scope_proto.child('Actions' [])
-    { _block(Scope_guard) } .try.switch(
-        [true :Result] {
-            Scope_guard.:result = const_fun(Result)
-            Scope_guard._after_success
-        }
-        [false :Exception] {
-            Scope_guard.:exception = const_fun(Exception)
-            Scope_guard._after_failure
-        }
-    )
-}
-
-:Scope_proto = value(
-    'Actions' []
-    'on_exit' { > :Scope_guard (:_block)
-        Scope_guard.Actions.push(_exit_action($_block))
-        Scope_guard
-    }
-    'on_success' { > :Scope_guard (:_block)
-        Scope_guard.Actions.push(_success_action($_block))
-        Scope_guard
-    }
-    'on_failure' { > :Scope_guard (:_block)
-        Scope_guard.Actions.push(_failure_action($_block))
-        Scope_guard
-    }
-    'auto_close' { > :Scope_guard (:Closeable)
-        Scope_guard.on_exit { Closeable.close }
-        Closeable
-    }
-    '_after_success' { > :Scope_guard
-        Scope_guard.Actions.empty?.then {
-            Scope_guard.result
-        } {
-            :Action = Scope_guard.Actions.pop
-            { Action.act_for_success } .try.switch(
-                [true :Result] {
-                    Scope_guard._after_success
-                }
-                [false :Exception] {
-                    Scope_guard.:exception = const_fun(Exception)
-                    Scope_guard._after_failure
-                }
-            )
-        }
-    }
-    '_after_failure' { > :Scope_guard
-        { Scope_guard.Actions.any? } .loop {
-            :Action = Scope_guard.Actions.pop
-            { Action.act_for_failure } .try.switch(
-                [false :New_exception] {
-                    Scope_guard.exception.addSuppressed(New_exception)
-                }
-            )
-        }
-        Scope_guard.exception.throw
-    }
-)
-
-:_exit_action = { (:_block)
-    value(
-        'act_for_failure' $_block
-        'act_for_success' $_block
-    )
-}
-
-:_success_action = { (:_block)
-    value(
-        'act_for_failure' {}
-        'act_for_success' $_block
-    )
-}
-
-:_failure_action = { (:_block)
-    value(
-        'act_for_failure' $_block
-        'act_for_success' {}
-    )
-}

File src/main/kink/TEST.kn

 # THE SOFTWARE.
 
 use('COMMON_PATTERN.and')
-use('SCOPE_GUARD')
+use('GUARD')
 use('THREAD_LOCAL_STORAGE')
 use('java.util.concurrent.atomic.AtomicLong')
 
             _pending_test_result(Self_test.Pending_reason)
         } {
             {
-                SCOPE_GUARD.guarding { (:Guard)
+                GUARD.guarding { (:Guard)
                     Self_test.Parent_virtual_group._register_nullify_set_up_refs(Guard)
                     Self_test.Parent_virtual_group._register_after_blocks(Guard)
                     Self_test.Parent_virtual_group._run_before_blocks

File src/main/kink/THREAD_LOCAL_STORAGE.kn

 use('SHOW_BUILDER')
 use('META.meta')
 use('JAVA.null')
-use('SCOPE_GUARD.guarding')
+use('GUARD.guarding')
 use('java.lang.ThreadLocal')
 use('java.lang.Thread')
 

File src/test/kink/GUARD_test.kn

+#!/usr/bin/env kink
+# vim: et sw=4 sts=4
+
+# Copyright (c) 2013 Miyakawa Taku
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+use('GUARD.guarding')
+use('TEST.test')
+use('CHECK.check_thrown')
+
+# Success
+test {
+    :List = []
+    :Result = guarding { (:Sg)
+        Sg
+        .on_exit { List.push('BBB') }
+        .on_failure { List.push('XXX') }
+        .on_success { List.push('AAA') }
+        'Result'
+    }
+    Result.check('Result')
+    List.check(['AAA' 'BBB'])
+}
+
+# Fail
+test {
+    :Exception = exception('Error!')
+    :List = []
+    :Thrown = check_thrown {
+        guarding { (:Sg)
+            Sg
+            .on_exit { List.push('BBB') }
+            .on_success { List.push('XXX') }
+            .on_failure { List.push('AAA') }
+            Exception.throw
+            Sg.on_exit { List.push('XXX') }
+        }
+    }
+    Thrown.check(Exception)
+    List.check(['AAA' 'BBB'])
+}
+
+# Fail on a handler
+test {
+    :Exception = exception('Error!')
+    :List = []
+    :Thrown = check_thrown {
+        guarding { (:Sg)
+            Sg
+            .on_exit { List.push('BBB') }
+            .on_success { List.push('XXX') }
+            .on_failure { List.push('AAA') }
+            .on_success { Exception.throw }
+            'Result'
+        }
+    }
+    Thrown.check(Exception)
+    List.check(['AAA' 'BBB'])
+}
+
+# Suppressed exception on a handler
+test {
+    :Exception = exception('Error!')
+    :Suppressed = exception('Suppressed!')
+    :List = []
+    :Thrown = check_thrown {
+        guarding { (:Sg)
+            Sg
+            .on_exit { List.push('BBB') }
+            .on_success { List.push('XXX') }
+            .on_failure { Suppressed.throw }
+            .on_failure { List.push('AAA') }
+            Exception.throw
+        }
+    }
+    Thrown.check(Exception)
+    Exception.getSuppressed.list.check([Suppressed])
+    List.check(['AAA' 'BBB'])
+}
+
+# Autoclose on success
+test {
+    :Closed? = false
+    :Closeable = value('close' { :Closed?.solid = true })
+    guarding { (:Sg)
+        :Ret = Sg.auto_close(Closeable)
+        Ret.check(Closeable)
+        'Result'
+    }
+    Closed?.check(true)
+}
+
+# Autoclose on failure
+test {
+    :Exception = exception('Error!')
+    :Closed? = false
+    :Closeable = value('close' { :Closed?.solid = true })
+    :Thrown = check_thrown {
+        guarding { (:Sg)
+            :Ret = Sg.auto_close(Closeable)
+            Ret.check(Closeable)
+            Exception.throw
+        }
+    }
+    Thrown.check(Exception)
+    Closed?.check(true)
+}
+
+# Get result
+test {
+    :Result = guarding { (:Sg)
+        Sg.on_success { Sg.result.check('Result') }
+        'Result'
+    }
+    Result.check('Result')
+}
+
+# Get exception
+test {
+    :Got_exception = ()
+    :Exception = exception('Exception')
+    :Thrown = check_thrown {
+        guarding { (:Sg)
+            Sg.on_failure { :Got_exception.solid = Sg.exception }
+            Exception.throw
+        }
+    }
+    Got_exception.check(Exception)
+    Thrown.check(Exception)
+}

File src/test/kink/SCOPE_GUARD_test.kn

-#!/usr/bin/env kink
-# vim: et sw=4 sts=4
-
-# Copyright (c) 2013 Miyakawa Taku
-# 
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-# 
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-use('SCOPE_GUARD.guarding')
-use('TEST.test')
-use('CHECK.check_thrown')
-
-# Success
-test {
-    :List = []
-    :Result = guarding { (:Sg)
-        Sg
-        .on_exit { List.push('BBB') }
-        .on_failure { List.push('XXX') }
-        .on_success { List.push('AAA') }
-        'Result'
-    }
-    Result.check('Result')
-    List.check(['AAA' 'BBB'])
-}
-
-# Fail
-test {
-    :Exception = exception('Error!')
-    :List = []
-    :Thrown = check_thrown {
-        guarding { (:Sg)
-            Sg
-            .on_exit { List.push('BBB') }
-            .on_success { List.push('XXX') }
-            .on_failure { List.push('AAA') }
-            Exception.throw
-            Sg.on_exit { List.push('XXX') }
-        }
-    }
-    Thrown.check(Exception)
-    List.check(['AAA' 'BBB'])
-}
-
-# Fail on a handler
-test {
-    :Exception = exception('Error!')
-    :List = []
-    :Thrown = check_thrown {
-        guarding { (:Sg)
-            Sg
-            .on_exit { List.push('BBB') }
-            .on_success { List.push('XXX') }
-            .on_failure { List.push('AAA') }
-            .on_success { Exception.throw }
-            'Result'
-        }
-    }
-    Thrown.check(Exception)
-    List.check(['AAA' 'BBB'])
-}
-
-# Suppressed exception on a handler
-test {
-    :Exception = exception('Error!')
-    :Suppressed = exception('Suppressed!')
-    :List = []
-    :Thrown = check_thrown {
-        guarding { (:Sg)
-            Sg
-            .on_exit { List.push('BBB') }
-            .on_success { List.push('XXX') }
-            .on_failure { Suppressed.throw }
-            .on_failure { List.push('AAA') }
-            Exception.throw
-        }
-    }
-    Thrown.check(Exception)
-    Exception.getSuppressed.list.check([Suppressed])
-    List.check(['AAA' 'BBB'])
-}
-
-# Autoclose on success
-test {
-    :Closed? = false
-    :Closeable = value('close' { :Closed?.solid = true })
-    guarding { (:Sg)
-        :Ret = Sg.auto_close(Closeable)
-        Ret.check(Closeable)
-        'Result'
-    }
-    Closed?.check(true)
-}
-
-# Autoclose on failure
-test {
-    :Exception = exception('Error!')
-    :Closed? = false
-    :Closeable = value('close' { :Closed?.solid = true })
-    :Thrown = check_thrown {
-        guarding { (:Sg)
-            :Ret = Sg.auto_close(Closeable)
-            Ret.check(Closeable)
-            Exception.throw
-        }
-    }
-    Thrown.check(Exception)
-    Closed?.check(true)
-}
-
-# Get result
-test {
-    :Result = guarding { (:Sg)
-        Sg.on_success { Sg.result.check('Result') }
-        'Result'
-    }
-    Result.check('Result')
-}
-
-# Get exception
-test {
-    :Got_exception = ()
-    :Exception = exception('Exception')
-    :Thrown = check_thrown {
-        guarding { (:Sg)
-            Sg.on_failure { :Got_exception.solid = Sg.exception }
-            Exception.throw
-        }
-    }
-    Got_exception.check(Exception)
-    Thrown.check(Exception)
-}

File src/test/kink/enhancertest/Path_test.kn

 use('CHECK.check_thrown')
 use('USING.using')
 use('JAVA.byte')
-use('SCOPE_GUARD.guarding')
+use('GUARD.guarding')
 use('java.nio.file.Path')
 use('java.nio.file.Paths')
 use('java.nio.file.Files')