diff options
author | Soumith Chintala <soumith@gmail.com> | 2016-09-15 20:32:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-15 20:32:23 +0300 |
commit | a22852344030a6a32dd804992477009bfad3de76 (patch) | |
tree | cdf71fec90aa74730187d48ad0720855ea082a99 | |
parent | 491d17c8a47b334bbee9a420694ad4637b49bbac (diff) | |
parent | 5a59a01dc67331dfde3f7753a3ca90c0755eb211 (diff) |
Merge pull request #192 from chunyang/master
Return a sensible error on unknown file type
-rw-r--r-- | assets/bmp-without-ext | bin | 0 -> 142 bytes | |||
-rw-r--r-- | init.lua | 2 | ||||
-rw-r--r-- | test/test.lua | 11 |
3 files changed, 13 insertions, 0 deletions
diff --git a/assets/bmp-without-ext b/assets/bmp-without-ext Binary files differnew file mode 100644 index 0000000..0d7f4eb --- /dev/null +++ b/assets/bmp-without-ext @@ -366,6 +366,8 @@ local function load(filename, depth, tensortype) local tensor if image.is_supported(ext) then tensor = filetypes[ext].loader(filename, depth, tensortype) + elseif not ext then + dok.error('unable to determine image type for file: ' .. filename, 'image.load') else dok.error('unknown image type: ' .. ext, 'image.load') end diff --git a/test/test.lua b/test/test.lua index 80299e9..0a25cd9 100644 --- a/test/test.lua +++ b/test/test.lua @@ -635,6 +635,17 @@ function test.test_pbmload() end ---------------------------------------------------------------------- +-- Load unknown image type without extension test +-- +function test.LoadUnknownImageTypeWithoutExtension() + tester:assertErrorPattern( + function() image.load(getTestImagePath("bmp-without-ext")) end, + "unable to determine image type for file", + "unknown image type should not be loaded or unexpected error message" + ) +end + +---------------------------------------------------------------------- -- Text drawing test -- function test.test_textdraw() |