1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2008 - DIGITEO - Allan CORNET
4// Copyright (C) 2020 - Stéphane MOTTELET
5//
6//  This file is distributed under the same license as the Scilab package.
7// =============================================================================
8
9// <-- CLI SHELL MODE -->
10// <-- NO CHECK REF -->
11
12mess = msprintf(_("%s: Wrong number of input argument(s): at most %d expected.\n"),"get_absolute_file_path",1)
13assert_checkerror("get_absolute_file_path(''test.sce'',''test.sce'')",mess);
14
15current_dir = pwd()+ filesep();
16
17a = mopen(TMPDIR+'/test.sce','wt');
18// get_absolute_file_path since 5.1.1 returns path with path separator @ the end
19d1 = get_absolute_file_path('test.sce');
20mclose(a);
21assert_checkequal(d1,TMPDIR + filesep());
22
23// file 'test.sce' closed then not found
24mess = msprintf(_("%s: The file %s is not opened in scilab.\n"),"get_absolute_file_path","test.sce");
25assert_checkerror("get_absolute_file_path(''test.sce'')",mess);
26
27// one input arg form, within new script
28mputl("filepath = get_absolute_file_path(""script1.sce"")",TMPDIR+'/script1.sce');
29exec(TMPDIR+'/script1.sce');
30assert_checkequal(filepath,TMPDIR + filesep());
31
32// one input arg form, within a function in a new script
33mputl(["function fp = test()"
34       "fp = get_absolute_file_path(""script2.sce"")"
35       "end"
36       "filepath = test()"],TMPDIR+'/script2.sce');
37exec(TMPDIR+'/script2.sce');
38assert_checkequal(filepath,TMPDIR + filesep());
39
40// no input arg form, within new script
41mputl("[filepath,filename] = get_absolute_file_path()",TMPDIR+'/script3.sce');
42exec(TMPDIR+'/script3.sce');
43assert_checkequal(filepath,TMPDIR + filesep());
44assert_checkequal(filename,"script3.sce");
45
46// no input arg form, within a function in a new script
47mputl(["function [fp,fn] = test()"
48       "[fp,fn] = get_absolute_file_path()"
49       "end"
50       "[filepath,filename] = test()"],TMPDIR+'/script4.sce');
51exec(TMPDIR+'/script4.sce');
52assert_checkequal(filepath,TMPDIR + filesep());
53assert_checkequal(filename,"script4.sce");
54
55// no input arg form, within current script
56// filepath is TMPDIR of scilab instance calling the test
57[filepath1,filename] = get_absolute_file_path();
58[filepath2] = get_absolute_file_path("get_absolute_file_path.tst");
59assert_checkequal(filename,"get_absolute_file_path.tst");
60assert_checkequal(filepath1,filepath2);
61
62