1;
2; various basic tests on FILE_INFO() based on FILE_TEST()
3; written by NATCHKEBIA Ilia, May 2015
4; under GNU GPL v2 or any later
5;
6; -----------------------------------------------
7;
8pro TEST_FILE_INFO, test=test, no_exit=no_exit, help=help
9;
10if KEYWORD_SET(help) then begin
11   print, 'pro TEST_FILE_INFO, test=test, no_exit=no_exit, help=help'
12   return
13endif
14;
15;Errors count is 0 at the beginning
16total_errors = 0
17;
18; Create test directory
19tdir='tdir_for_FILE_INFO'
20SPAWN, 'mkdir '+tdir
21dirInfo=FILE_INFO(tdir)
22;
23; various tests
24;
25if (dirInfo.name NE tdir) then ERRORS_ADD, total_errors, 'bad dir. name'
26if (dirInfo.exists NE 1) then ERRORS_ADD, total_errors, 'Dir. not detected'
27if (dirInfo.directory NE 1) then ERRORS_ADD, total_errors, 'Dir. not considered as Dir'
28;Test if it is symlink
29if (dirInfo.symlink NE 0) then ERRORS_ADD, total_errors, 'Dir. is considered as symlink'
30;
31;Create test folder symlink
32tdirsym='testSymlinkDirectory_for_FILE_INFO'
33SPAWN, 'ln -s '+tdir+" "+tdirsym
34;info
35dirsyminfo=FILE_INFO(tdirsym)
36;Test if it exists
37if (dirsyminfo.exists NE 1) then ERRORS_ADD, total_errors, 'symlink of Dir. not detected'
38;Test if it is symlink of directory
39if (dirsyminfo.directory NE 1) then ERRORS_ADD, total_errors, 'symlink of Dir. not considered as Dir.'
40;Test if it is symlink
41if (dirsyminfo.symlink NE 1) then ERRORS_ADD, total_errors, 'symlink is not considered as symlink'
42;Remove test directory and symlink
43SPAWN, 'rm -r '+tdir
44SPAWN, 'rm '+tdirsym
45;
46;
47;Create test file
48tfile='tfile_for_FILE_INFO'
49SPAWN, 'touch '+tfile
50;info
51fileinfo=FILE_INFO(tfile)
52;Test if it exists
53if (fileinfo.exists NE 1) then ERRORS_ADD, total_errors, 'file not detected'
54;Test if it is directory
55if (fileinfo.directory NE 0) then ERRORS_ADD, total_errors, 'file is considered as Dir.'
56;Test if it is symlink
57if (fileinfo.symlink NE 0) then ERRORS_ADD, total_errors, 'file is considered as symlink'
58;
59;Create test file symlink
60tfilesym='testSymlinkFile_for_FILE_INFO'
61SPAWN, 'ln -s '+tfile+" "+tfilesym
62;info
63filesyminfo=FILE_INFO(tfilesym)
64;Test if it exists
65if (filesyminfo.exists NE 1) then ERRORS_ADD, total_errors, 'symlink of file not detected'
66;Test if it is symlink of directory
67if (filesyminfo.directory NE 0) then ERRORS_ADD, total_errors, 'symlink of file is considered as Dir.'
68;Test if it is symlink
69if (filesyminfo.symlink NE 1) then ERRORS_ADD, total_errors, 'symlink of file is not considered as symlink'
70;Remove test file and symlink
71SPAWN, 'rm '+tfile
72SPAWN, 'rm '+tfilesym
73;
74; final message
75;
76BANNER_FOR_TESTSUITE, 'TEST_FILE_INFO', total_errors
77;
78if KEYWORD_SET(test) then STOP
79;
80if (total_errors GT 0) AND ~KEYWORD_SET(no_exit) then EXIT, status=1
81;
82end
83