Script generates LUA file that can be executed
This commit is contained in:
parent
81c3dabd79
commit
cf93603efc
4668
unit/generateTimesMarchOctober.lua
Executable file
4668
unit/generateTimesMarchOctober.lua
Executable file
File diff suppressed because it is too large
Load Diff
40
unit/generateTimesMarchOctober.sh
Executable file
40
unit/generateTimesMarchOctober.sh
Executable file
@ -0,0 +1,40 @@
|
||||
#/bin/bash
|
||||
|
||||
# date command is all we need, as shown:
|
||||
#date -d '2007-011-01 17:30:24' '+%:z'
|
||||
#+01:00
|
||||
|
||||
HEAD=timetest_head.template
|
||||
TAIL=timetest_tail.template
|
||||
# remote the tailing "./" and the extension of this script
|
||||
OUTPUT="$(echo "$0" | sed 's;^./;;' | cut -d'.' -f1).lua"
|
||||
|
||||
echo "Generating $OUTPUT ..."
|
||||
|
||||
cat $HEAD > $OUTPUT
|
||||
# Logic to generate the script
|
||||
for year in {2016..2018}; do
|
||||
for month in 3 10; do
|
||||
for day in {1..31}; do
|
||||
hour=$((RANDOM%24))
|
||||
for minutes in {0..24}; do
|
||||
seconds=$((RANDOM%60))
|
||||
timestmp="$year-$month-$day $hour:$minutes:$seconds"
|
||||
date -d "$timestmp" "+%F %T" >> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "--Time $timestmp is not valid" >> $OUTPUT
|
||||
else
|
||||
# Result of date looks like +01:00
|
||||
# Grep extracts the hour, then remove the plus in front and at the end remove leading zeros
|
||||
offset=$(date -d "$timestmp" '+%:z' | grep -o "+[0-9]*" | sed 's/+//' | sed 's/^0//')
|
||||
dayofweek=$(date -d "$timestmp" '+%u')
|
||||
# Generate the lua test command, like: checkTime(2015, 1, 1, 10, 11, 12, 0, 1)
|
||||
echo "checkTime($year, $month, $day, $hour, $minutes, $seconds, $dayofweek, $offset)" >> $OUTPUT
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
cat $TAIL >> $OUTPUT
|
||||
|
||||
exit 0
|
15
unit/timetest_head.template
Normal file
15
unit/timetest_head.template
Normal file
@ -0,0 +1,15 @@
|
||||
-- Simple unit test to test time zones
|
||||
|
||||
dofile("../timecore.lua")
|
||||
|
||||
function checkTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn,dowIn, resultingHourDiff)
|
||||
year, month, day, hour, minutes, seconds = getLocalTime(yearIn, monthIn, dayIn, hourIn, minutesIn, secondsIn, dowIn)
|
||||
|
||||
if not (year == yearIn and monthIn == month and day == dayIn and hour == (hourIn + resultingHourDiff) and minutesIn == minutes and secondsIn == seconds ) then
|
||||
print(yearIn .. "-" .. string.format("%0.2d", monthIn) .. "-" .. string.format("%0.2d", dayIn) .. " " .. string.format("%0.2d", hourIn) .. ":" .. string.format("%0.2d", minutesIn) .. ":" .. string.format("%0.2d", secondsIn) .. " (" .. dowIn .. ".th dayOfWeek) not as expected GMT+" .. resultingHourDiff .. " but GMT+" .. (hour - hourIn) )
|
||||
os.exit(1)
|
||||
else
|
||||
print(yearIn .. "-" .. string.format("%0.2d", monthIn) .. "-" .. string.format("%0.2d", dayIn) .. " " .. string.format("%0.2d", hourIn) .. ":" .. string.format("%0.2d", minutesIn) .. ":" .. string.format("%0.2d", secondsIn) .. " is GMT+" .. resultingHourDiff )
|
||||
end
|
||||
end
|
||||
|
3
unit/timetest_tail.template
Normal file
3
unit/timetest_tail.template
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
print "Finished with all tests"
|
||||
os.exit(0)
|
Loading…
Reference in New Issue
Block a user