zombiezen.com/go/lua@v0.0.0-20231013005828-290725fb9140/testdata/oslib.lua (about)

     1  -- Copyright 2023 Ross Light
     2  --
     3  -- Permission is hereby granted, free of charge, to any person obtaining a copy of
     4  -- this software and associated documentation files (the “Software”), to deal in
     5  -- the Software without restriction, including without limitation the rights to
     6  -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
     7  -- the Software, and to permit persons to whom the Software is furnished to do so,
     8  -- subject to the following conditions:
     9  --
    10  -- The above copyright notice and this permission notice shall be included in all
    11  -- copies or substantial portions of the Software.
    12  --
    13  -- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    15  -- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    16  -- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    17  -- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    18  -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    19  --
    20  -- SPDX-License-Identifier: MIT
    21  
    22  -- Test suite for this package's os library implementation.
    23  
    24  -- os.date
    25  assert(os.date() == "Sun Sep 24 13:58:07 2023")
    26  assert(os.date("!%c") == "Sun Sep 24 20:58:07 2023")
    27  local timeTable = os.date("*t")
    28  assert(timeTable.year == 2023)
    29  assert(timeTable.month == 9)
    30  assert(timeTable.day == 24)
    31  assert(timeTable.hour == 13)
    32  assert(timeTable.min == 58)
    33  assert(timeTable.sec == 7)
    34  assert(timeTable.wday == 1)
    35  assert(timeTable.yday == 267)
    36  assert(timeTable.isdst == true or timeTable.isdist == nil)
    37  
    38  -- os.execute
    39  local success, exitType, exitStatus = os.execute("true")
    40  assert(success)
    41  assert(exitType == "exit")
    42  assert(exitStatus == 0)
    43  success, exitType, exitStatus = os.execute("false")
    44  assert(not success)
    45  assert(exitType == "exit")
    46  assert(exitStatus == 1)
    47  
    48  -- os.getenv
    49  assert(os.getenv("FOO") == "BAR")
    50  assert(os.getenv("EMPTY") == "")
    51  assert(not os.getenv("BORK"))
    52  
    53  -- os.remove
    54  assert(os.remove("foo.txt"))
    55  assert(not os.remove("doesnotexist"))
    56  
    57  -- os.rename
    58  assert(os.rename("old", "new"))
    59  assert(not os.rename("doesnotexist", "foo"))
    60  
    61  -- os.time and os.difftime
    62  local t1 = os.time()
    63  assert(type(t1) == "number")
    64  local t2 = os.time{
    65    year = 2023, month = 9, day = 24,
    66    hour = 13, min = 1, sec = 0,
    67  }
    68  assert(type(t2) == "number")
    69  local dt = os.difftime(t1, t2)
    70  assert(dt == 3427)
    71  
    72  assert(os.date(nil, t2) == "Sun Sep 24 13:01:00 2023")