Ejemplo n.º 1
0
 def test_output_make_make(self):
     # mf needs to set just_print to false in order to test mf2
     mf = Makefile('Makefile', '', False)
     mf.run_makefile()
     mf2 = Makefile('Makefile', '', True)
     mf2.run_makefile()
     correct = []
     self.assertEqual(mf2.output, correct)
Ejemplo n.º 2
0
 def test_output_make_solution_cpp(self):
     mf = Makefile('Makefile', 'solution', True)
     mf.run_makefile()
     correct = [
         'g++ solution.cpp -g -Wall -std=gnu++11 -o solution',
         'touch test.xyz'
     ]
     self.assertEqual(mf.output, correct)
Ejemplo n.º 3
0
 def test_output_make_all(self):
     mf = Makefile('Makefile', '', True)
     mf.run_makefile()
     correct = [
         'gcc -std=gnu99 -Wall -c -o hello.o hello.c',
         'gcc -std=gnu99 -Wall -c -o main.o main.c',
         'gcc -o hello main.o hello.o'
     ]
     self.assertEqual(mf.output, correct)
Ejemplo n.º 4
0
def main():
    args = read_arguments()
    if args.file:
        # if -f flag was used to specify the makefile
        file_name = args.file
        # quit if this is not a valid file path
        if not os.path.exists(file_name) or not os.path.isfile(file_name):
            error('The file {} could not be found.'.format(file_name))
    else:
        file_name = ''
        # search the current directory for a makefile
        for path in os.listdir(os.getcwd()):
            if os.path.isfile(path):
                if os.path.basename(path).lower() == 'makefile':
                    file_name = path
                    break
        # quit if no makefile was found
        if not file_name:
            error('Makefile not found.')

    mkfile = Makefile(file_name, args.target, args.just_print)
    mkfile.run_makefile()
Ejemplo n.º 5
0
 def test_output_make_clean_make(self):
     mf = Makefile('Makefile', '', False)
     mf.run_makefile()
     mf2 = Makefile('Makefile', 'clean', False)
     mf2.run_makefile()
     mf3 = Makefile('Makefile', '', True)
     mf3.run_makefile()
     correct = [
         'gcc -std=gnu99 -Wall -c -o hello.o hello.c',
         'gcc -std=gnu99 -Wall -c -o main.o main.c',
         'gcc -o hello main.o hello.o'
     ]
     self.assertEqual(mf3.output, correct)
Ejemplo n.º 6
0
 def tearDown(self):
     # removes files left after a method e.x. test_output_make_make
     mf = Makefile('Makefile', 'clean', False)
     mf.run_makefile()
Ejemplo n.º 7
0
 def test_cycle(self):
     mf = Makefile('Makefile', 'cycle', True)
     # sys.exit should be called
     with self.assertRaises(SystemExit):
         mf.run_makefile()
Ejemplo n.º 8
0
 def test_output_make_clean(self):
     mf = Makefile('Makefile', 'clean', True)
     mf.run_makefile()
     correct = ['rm solution test.xyz']
     self.assertEqual(mf.output, correct)
Ejemplo n.º 9
0
 def test_output_make_clean(self):
     mf = Makefile('Makefile', 'clean', True)
     mf.run_makefile()
     correct = ['rm -f hello *.o']
     self.assertEqual(mf.output, correct)